// In the name of God
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define sz(a) int(a.size())
#define all(v) v.begin(), v.end()
#define bpc(v) __builtin_popcountll(v)
#define IOS ios_base :: sync_with_stdio(false); cin.tie(NULL);
#define itr iterator
#define rep(i, a, b) for (int i = a; i <= b; ++i)
#define per(i, a, b) for (int i = a; i >= b; --i)
#define ub upper_bound
#define lb lower_bound
const int N = 3e3 + 5;
const int inf = 1e9 + 1;
const int mod = 1e9 + 7;
const double eps = 1e-15;
const int pw = 257;
int n, m, dp[N][N][2], ans;
string s[N];
bool check(int i, int j, bool o) {
if (!o)
return (i + 2 <= n && s[i][j] == 'R' && s[i + 1][j] == 'G' && s[i + 2][j] == 'W');
else
return (j + 2 <= m && s[i][j] == 'R' && s[i][j + 1] == 'G' && s[i][j + 2] == 'W');
}
int main() {
#ifdef Madi
freopen(".in", "r", stdin);
freopen(".out", "w", stdout);
#endif
IOS
cin >> n >> m;
rep(i, 1, n) {
cin >> s[i];
s[i] = '$' + s[i];
}
per(i, n, 1) {
rep(j, 1, m) {
dp[i][j][0] = max(dp[i][j][0], dp[i + 1][j - 1][0] + check(i, j, 0));
dp[i][j][1] = max(dp[i][j][1], max(dp[i + 1][j - 1][0], dp[i + 1][j - 1][1]) + check(i, j, 1));
if (i == 1 || j == m)
ans += max(dp[i][j][0], dp[i][j][1]);
//cout << i << ' ' << j << ' ' << dp[i][j][0] << ' ' << dp[i][j][1] << "\n";
}
}
cout << ans;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
612 KB |
Output is correct |
9 |
Correct |
2 ms |
612 KB |
Output is correct |
10 |
Correct |
2 ms |
612 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
2 ms |
612 KB |
Output is correct |
13 |
Correct |
2 ms |
612 KB |
Output is correct |
14 |
Correct |
2 ms |
612 KB |
Output is correct |
15 |
Correct |
2 ms |
612 KB |
Output is correct |
16 |
Correct |
2 ms |
612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
612 KB |
Output is correct |
9 |
Correct |
2 ms |
612 KB |
Output is correct |
10 |
Correct |
2 ms |
612 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
2 ms |
612 KB |
Output is correct |
13 |
Correct |
2 ms |
612 KB |
Output is correct |
14 |
Correct |
2 ms |
612 KB |
Output is correct |
15 |
Correct |
2 ms |
612 KB |
Output is correct |
16 |
Correct |
2 ms |
612 KB |
Output is correct |
17 |
Correct |
2 ms |
684 KB |
Output is correct |
18 |
Correct |
2 ms |
684 KB |
Output is correct |
19 |
Correct |
1 ms |
704 KB |
Output is correct |
20 |
Correct |
2 ms |
704 KB |
Output is correct |
21 |
Correct |
2 ms |
752 KB |
Output is correct |
22 |
Incorrect |
2 ms |
756 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
380 KB |
Output is correct |
2 |
Correct |
2 ms |
484 KB |
Output is correct |
3 |
Correct |
2 ms |
532 KB |
Output is correct |
4 |
Correct |
2 ms |
588 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
2 ms |
604 KB |
Output is correct |
7 |
Correct |
2 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
612 KB |
Output is correct |
9 |
Correct |
2 ms |
612 KB |
Output is correct |
10 |
Correct |
2 ms |
612 KB |
Output is correct |
11 |
Correct |
2 ms |
612 KB |
Output is correct |
12 |
Correct |
2 ms |
612 KB |
Output is correct |
13 |
Correct |
2 ms |
612 KB |
Output is correct |
14 |
Correct |
2 ms |
612 KB |
Output is correct |
15 |
Correct |
2 ms |
612 KB |
Output is correct |
16 |
Correct |
2 ms |
612 KB |
Output is correct |
17 |
Correct |
2 ms |
684 KB |
Output is correct |
18 |
Correct |
2 ms |
684 KB |
Output is correct |
19 |
Correct |
1 ms |
704 KB |
Output is correct |
20 |
Correct |
2 ms |
704 KB |
Output is correct |
21 |
Correct |
2 ms |
752 KB |
Output is correct |
22 |
Incorrect |
2 ms |
756 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |