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;
int N, M, ans;
char a[3010][3010];
int validG(int x, int y) {
if (a[x-1][y] == 'R' && a[x][y] == 'G' && a[x+1][y] == 'W') return 1;
if (a[x][y-1] == 'R' && a[x][y] == 'G' && a[x][y+1] == 'W') return 2;
return false;
}
bool overlap(int x, int y) {
return (validG(x,y) + validG(x-1,y+1) == 3);
}
int main()
{
cin >> N >> M;
for(int i=1; i<=N; i++) {
for(int j=1; j<=M; j++) {
cin >> a[i][j];
}
}
for(int i=1; i<=N; i++) {
int x = i;
int y = 1;
while(x>=1 && y<=M) {
if (validG(x,y)) {
ans++;
if(overlap(x,y)) {
x--;
y++;
}
}
x--;
y++;
}
}
for(int j=2; j<=M; j++) {
int x = N;
int y = j;
while(x>=1 && y<=M) {
if (validG(x,y)) {
ans++;
if(overlap(x,y)) {
x--;
y++;
}
}
x--;
y++;
}
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |