C – Jack-Jack and Matrices


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Do you know Jack-Jack? He is the youngest child of Parr family. The Parr family consists of Bob, Helen, Violet, Dashiell, and Jack-Jack. They are all characters of the “The Incredibles Movie”. Jack-Jack has many superpowers. Some of them are still not discovered yet. Recently, Helen saw Jack-Jack playing with matrices.

Jack-Jack thinks each cell of a matrix is powerful if it has three neighbors, which sum of their values is a power of two. Two cells are neighbors if and only if they share a side or corner. Jack-Jack is superhero, he is not a programmer. Can you count the number of powerful cells of the matrix for him?

ورودی🔗

The first line of input contains two space separated integers NN, MM – the number of rows and the number of columns of the matrix.

1N,M10001 \leq N, M \leq 1000

In each of the next NN lines, there are MM space-separated integers each representing a cell of the matrix. The value each cell is a non-negative integer that does not exceed 10610^6.

خروجی🔗

For each test, print a single integer, the number of powerful cells in the matrix.

مثال‌ها🔗

ورودی نمونه ۱🔗

4 3
3 3 3
3 3 4
1 1 1
1 1 1
Plain text

خروجی نمونه ۱🔗

3
Plain text

ورودی نمونه ۲🔗

1 1
3
Plain text

خروجی نمونه ۲🔗

0
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.