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;
char grid[3000][3000];
int N, M;
bool vert(int i, int j)
{
if(i == 0 || i == N-1) return 0;
if(grid[i-1][j] != 'R') return 0;
if(grid[i][j] != 'G') return 0;
if(grid[i+1][j] != 'W') return 0;
return 1;
}
bool horiz(int i, int j)
{
if(j == 0 || j == M-1) return 0;
if(grid[i][j-1] != 'R') return 0;
if(grid[i][j] != 'G') return 0;
if(grid[i][j+1] != 'W') return 0;
return 1;
}
int main()
{
cin >> N >> M;
for(int i = 0; i < N; i++) for(int j = 0; j < M; j++) cin >> grid[i][j];
int res = 0;
int H, V;
int H1, V1;
for(int I = 0; I < N; I++)
{
H = 0;
V = 0;
for(int s = 0; I-s >= 0 && s < M; s++)
{
swap(H, H1);
swap(V, V1);
int i = I-s;
int j = s;
H = max(H1, V1);
H = max(H, H1 + horiz(i, j));
V = max(H1, V1);
V = max(V, V1 + vert(i, j));
}
// cout << H << ' ' << V << '\n';
res += max(H, V);
}
for(int J = 1; J < M; J++)
{
H = 0;
V = 0;
for(int s = 0; N-1-s >= 0 && J+s < M; s++)
{
swap(H, H1);
swap(V, V1);
int i = N-1-s;
int j = J+s;
H = max(H1, V1);
H = max(H, H1 + horiz(i, j));
V = max(H1, V1);
V = max(V, V1 + vert(i, j));
}
// cout << H << ' ' << V << '\n';
res += max(H, V);
}
cout << res << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |