#include <bits/stdc++.h>
using namespace std;
using pint = array <int, 2>;
using tint = array <int, 3>;
const int mxN = 3001;
char A[mxN][mxN];
int n, m, ans = 0;
bool vst[2][mxN][mxN], adj[2][mxN][mxN][3];
int main()
{
scanf("%d %d", &n, &m);
for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf(" %c", &A[i][j]);
for (int i = 1; i <= n - 2; i++) {
for (int j = 1; j <= m; j++){
if (A[i][j] == 'R' && A[i + 1][j] == 'G' && A[i + 2][j] == 'W') vst[1][i][j] = true;
}
}
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m - 2; j++){
if (!(A[i][j] == 'R' && A[i][j + 1] == 'G' && A[i][j + 2] == 'W')) continue;
vst[0][i][j] = true;
if (i + 2 <= n && vst[1][i][j]){
adj[0][i][j][0] = 1;
adj[1][i][j][0] = 1;
}
if (i - 1 >= 1 && i + 1 <= n && vst[1][i - 1][j + 1]){
adj[0][i][j][1] = 1;
adj[1][i - 1][j + 1][1] = 1;
}
if (i - 2 >= 1 && vst[1][i - 2][j + 2]){
adj[0][i][j][2] = 1;
adj[1][i - 2][j + 2][2] = 1;
}
}
}
for (int b : {0, 1}){
for (int i = 1; i <= n; i++){
for (int j = 1; j <= m; j++){
if (!vst[b][i][j]) continue;
pint ret = {0, 0};
queue <tint> q;
q.push({b, i, j});
vst[b][i][j] = false;
while (!q.empty()){
tint cur = q.front(); q.pop();
ret[cur[0]]++;
vector <tint> nxt;
if (!cur[0] && adj[cur[0]][cur[1]][cur[2]][0]) nxt.push_back({1, cur[1], cur[2]});
if (!cur[0] && adj[cur[0]][cur[1]][cur[2]][1]) nxt.push_back({1, cur[1] - 1, cur[2] + 1});
if (!cur[0] && adj[cur[0]][cur[1]][cur[2]][2]) nxt.push_back({1, cur[1] - 2, cur[2] + 2});
if (cur[0] && adj[cur[0]][cur[1]][cur[2]][0]) nxt.push_back({0, cur[1], cur[2]});
if (cur[0] && adj[cur[0]][cur[1]][cur[2]][1]) nxt.push_back({0, cur[1] + 1, cur[2] - 1});
if (cur[0] && adj[cur[0]][cur[1]][cur[2]][2]) nxt.push_back({0, cur[1] + 2, cur[2] - 2});
for (tint elm : nxt){
if (!vst[elm[0]][elm[1]][elm[2]]) continue;
vst[elm[0]][elm[1]][elm[2]] = false;
q.push({elm[0], elm[1], elm[2]});
}
}
ans += max(ret[0], ret[1]);
}
}
}
printf("%d\n", ans);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
12 | scanf("%d %d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~~
dango_maker.cpp:13:68: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | for (int i = 1; i <= n; i++) for (int j = 1; j <= m; j++) scanf(" %c", &A[i][j]);
| ~~~~~^~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |