This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<iostream>
using namespace std;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
const int MAXN = 2010;
int n, m, ans, sum[2*MAXN][2*MAXN], pr[MAXN][MAXN];
bool arr[MAXN][MAXN];
inline int su(int x1, int y1, int x2, int y2){
return sum[x1][y1]+sum[x2][y2]-sum[x1][y2]-sum[x2][y1];
}
bool test_diamond(int cx, int cy, int sz){
if(sz<=0 || cx<sz || cy<sz || cx>=n-sz || cy>=m-sz) return false;
int x=cx+cy+1, y=cx-cy+m;
int s1 = su(x-sz-1, y-sz-1, x+sz, y+sz);
int s2 = su(x-sz, y-sz, x+sz-1, y+sz-1);
return s1==(sz<<2) && s2==0;
}
int main(){
scanf("%d %d", &n, &m);
forn(i, n) forn(j, m){
char ch; scanf(" %c", &ch);
sum[i+j+1][i-j+m] = arr[i][j] = (ch=='#');
}
forn(i, n+m) forn(j, n+m) sum[i+1][j+1]+=sum[i+1][j]+sum[i][j+1]-sum[i][j];
forn(i, n){
int lst = -1;
forn(j, m){
if(arr[i][j]) lst=j;
pr[i][j]=lst;
}
}
forn(i, n) forn(j, m) ans+=test_diamond(i, j, j - pr[i][j]);
printf("%d\n", ans);
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:22:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
22 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
Main.cpp:24:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
24 | char ch; scanf(" %c", &ch);
| ~~~~~^~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |