#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<string> vs;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
#define all(x) x.begin(), x.end()
#define rep(i,a,b) for(int i = a; i < b; i++)
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M;
cin >> N;
cin >> M;
vector<string> board(N);
rep(n,0,N) cin >> board[n];
vi Ns(N*M);
vi Ms(N*M);
int i = 0;
rep(dist,0,N+M) {
for(int m = max(0,dist-N+1); m <= min(dist,M-1); m++, i++) {
int n = dist-m;
Ns[i] = n;
Ms[i] = m;
}
}
vvi best(N*M, vi(3));
for(i = 0; i < N*M; i++) {
int n = Ns[i];
int m = Ms[i];
if(i > 0) {
best[i][0] = best[i-1][0];
best[i][1] = best[i-1][0];
best[i][2] = max(best[i-1][1], best[i-1][2]);
}
if(n+2 < N && board[n][m] == 'R' && board[n+1][m] == 'G' && board[n+2][m] == 'W') { // vertical
if(i == 0) best[i][0] = best[i][1] = best[i][2] = 1;
if(i-1 >= 0 && m-1 >= 0) best[i][2] = max(best[i][2], best[i-1][2]+1);
if(i-2 >= 0 && m-2 >= 0) best[i][2] = max(best[i][2], best[i-2][1]+1);
if(i-3 >= 0 && m-3 >= 0) best[i][2] = max(best[i][2], best[i-3][0]+1);
}
if(m+2 < M && board[n][m] == 'R' && board[n][m+1] == 'G' && board[n][m+2] == 'W') { // horizontal
if(i == 0) best[i][0] = best[i][1] = best[i][2] = 1;
else best[i][0] = max(best[i][0], best[i-1][0]+1);
}
best[i][1] = max(best[i][1], best[i][2]);
best[i][0] = max(best[i][0], best[i][1]);
}
cout << best[N*M-1][0] << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
376 KB |
Output is correct |
7 |
Correct |
2 ms |
376 KB |
Output is correct |
8 |
Correct |
2 ms |
376 KB |
Output is correct |
9 |
Correct |
2 ms |
376 KB |
Output is correct |
10 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
11 |
Halted |
0 ms |
0 KB |
- |