이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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);
}
컴파일 시 표준 에러 (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... |