// 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] = dp[i + 1][j - 1][0] + check(i, j, 0);
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;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
480 KB |
Output is correct |
3 |
Correct |
2 ms |
480 KB |
Output is correct |
4 |
Correct |
2 ms |
568 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
656 KB |
Output is correct |
9 |
Correct |
1 ms |
656 KB |
Output is correct |
10 |
Correct |
2 ms |
656 KB |
Output is correct |
11 |
Correct |
1 ms |
712 KB |
Output is correct |
12 |
Correct |
1 ms |
712 KB |
Output is correct |
13 |
Correct |
2 ms |
712 KB |
Output is correct |
14 |
Correct |
1 ms |
712 KB |
Output is correct |
15 |
Correct |
1 ms |
712 KB |
Output is correct |
16 |
Correct |
1 ms |
712 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
480 KB |
Output is correct |
3 |
Correct |
2 ms |
480 KB |
Output is correct |
4 |
Correct |
2 ms |
568 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
656 KB |
Output is correct |
9 |
Correct |
1 ms |
656 KB |
Output is correct |
10 |
Correct |
2 ms |
656 KB |
Output is correct |
11 |
Correct |
1 ms |
712 KB |
Output is correct |
12 |
Correct |
1 ms |
712 KB |
Output is correct |
13 |
Correct |
2 ms |
712 KB |
Output is correct |
14 |
Correct |
1 ms |
712 KB |
Output is correct |
15 |
Correct |
1 ms |
712 KB |
Output is correct |
16 |
Correct |
1 ms |
712 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
732 KB |
Output is correct |
21 |
Correct |
2 ms |
732 KB |
Output is correct |
22 |
Incorrect |
2 ms |
732 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
1 ms |
480 KB |
Output is correct |
3 |
Correct |
2 ms |
480 KB |
Output is correct |
4 |
Correct |
2 ms |
568 KB |
Output is correct |
5 |
Correct |
2 ms |
604 KB |
Output is correct |
6 |
Correct |
1 ms |
604 KB |
Output is correct |
7 |
Correct |
1 ms |
604 KB |
Output is correct |
8 |
Correct |
2 ms |
656 KB |
Output is correct |
9 |
Correct |
1 ms |
656 KB |
Output is correct |
10 |
Correct |
2 ms |
656 KB |
Output is correct |
11 |
Correct |
1 ms |
712 KB |
Output is correct |
12 |
Correct |
1 ms |
712 KB |
Output is correct |
13 |
Correct |
2 ms |
712 KB |
Output is correct |
14 |
Correct |
1 ms |
712 KB |
Output is correct |
15 |
Correct |
1 ms |
712 KB |
Output is correct |
16 |
Correct |
1 ms |
712 KB |
Output is correct |
17 |
Correct |
2 ms |
732 KB |
Output is correct |
18 |
Correct |
2 ms |
732 KB |
Output is correct |
19 |
Correct |
2 ms |
732 KB |
Output is correct |
20 |
Correct |
2 ms |
732 KB |
Output is correct |
21 |
Correct |
2 ms |
732 KB |
Output is correct |
22 |
Incorrect |
2 ms |
732 KB |
Output isn't correct |
23 |
Halted |
0 ms |
0 KB |
- |