#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
using namespace std;
#define int long long
#define nl '\n'
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
const int mod = 1000000007, mod2 = 998244353;
// change this
const int N = 3005;
int n, m, h[N][N], w[N][N];
char arr[N][N];
bool checkh(int i, int j) {
if (j < 3) return false;
return (arr[i][j-2] == 'R' && arr[i][j-1] == 'G' && arr[i][j] == 'W');
}
bool checkv(int i, int j) {
if (i < 3) return false;
return (arr[i-2][j] == 'R' && arr[i-1][j] =='G' && arr[i][j] == 'W');
}
int conf(int i, int j) {
if (i < 3 or j < 3) return 0;
vector< vector<int> > check = {
{i-2, j-1, i-1, j-2},
{i-2, j, i-1, j-1},
{i-1, j-1, i, j-2},
{i-1, j, i, j-1},
{i-2, j, i, j-2}
};
for (auto x : check) {
// check h change
int hc = h[x[0]][x[1]] - h[x[0]-1][x[1]] - h[x[0]][x[1]-1] + h[x[0]-1][x[1]-1];
// check w change
int wc = w[x[2]][x[3]] - w[x[2]-1][x[3]] - w[x[2]][x[3]-1] + w[x[2]-1][x[3]-1];
if (hc && wc) return -1;
}
return 0;
}
signed main() {
io;
cin >> n >> m;
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
cin >> arr[i][j];
h[i][j] = (h[i-1][j] + h[i][j-1] - h[i-1][j-1]) + conf(i, j);
w[i][j] = (w[i-1][j] + w[i][j-1] - w[i-1][j-1]);
if (checkh(i, j)) {
int nh = 1 + h[i][j-3] + h[i-1][j] - h[i-1][j-3];
int nw = w[i][j-3] + w[i-1][j] - w[i-1][j-3];
if (nh + nw > h[i][j] + w[i][j]) {
h[i][j] = nh;
w[i][j] = nw;
}
}
if (checkv(i, j)) {
int nh = h[i-3][j] + h[i][j-1] - h[i-3][j-1];
int nw = 1 + w[i-3][j] + w[i][j-1] - w[i-3][j-1];
if (nh + nw > h[i][j] + w[i][j]) {
h[i][j] = nh;
w[i][j] = nw;
}
}
// cout << h[i][j] + w[i][j] << ' ';
}
// cout << nl;
}
cout << h[n][m] + w[n][m] << nl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
376 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
6 |
Correct |
1 ms |
364 KB |
Output is correct |
7 |
Correct |
1 ms |
364 KB |
Output is correct |
8 |
Correct |
1 ms |
364 KB |
Output is correct |
9 |
Correct |
1 ms |
364 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
12 |
Halted |
0 ms |
0 KB |
- |