/* be name khoda */
// #define long_enable
#include <iostream>
#include <algorithm>
#include <cstring>
#include <numeric>
#include <vector>
#include <fstream>
#include <set>
#include <map>
using namespace std;
#ifdef long_enable
typedef long long int ll;
#else
typedef int ll;
#endif
typedef pair<ll, ll> pii;
typedef pair<pii, ll> ppi;
typedef pair<ll, pii> pip;
typedef vector<ll> vi;
typedef vector<pii> vpii;
#define forifrom(i, s, n) for (ll i = s; i < n; ++i)
#define forirto(i, n, e) for (ll i = (n) - 1; i >= e; --i)
#define fori(i, n) forifrom (i, 0, n)
#define forir(i, n) forirto (i, n, 0)
#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define smin(a, b) a = min(a, (b))
#define smax(a, b) a = max(a, (b))
#define debug(x) cout << #x << " -> " << (x) << endl
#define debug2(x, y) cout << #x << ' ' << #y << " -> " << (x) << ' ' << (y) << endl
#define debug3(x, y, z) cout << #x << ' ' << #y << ' ' << #z << " -> " << (x) << ' ' << (y) << ' ' << (z) << endl
#define debug4(x, y, z, t) cout << #x << ' ' << #y << ' ' << #z << ' ' << #t << " -> " << (x) << ' ' << (y) << ' ' << (z) << ' ' << (t) << endl
#define debuga(x, n) cout << #x << " -> "; fori (i1_da, n) { cout << (x)[i1_da] << ' '; } cout << endl
#define debugaa(x, n, m) cout << #x << " ->\n"; fori (i1_daa, n) { fori (i2_daa, m) { cout << (x)[i1_daa][i2_daa] << ' '; } cout << '\n'; } cout << endl
const ll MOD = 1000000007;
const ll INF = 2000000000;
const long long BIG = 1446803456761533460LL;
#define XL (x << 1)
#define XR (XL | 1)
#define MD ((l + r) >> 1)
#define Add(a, b) a = ((a) + (b)) % MOD
#define Mul(a, b) a = (1LL * (a) * (b)) % MOD
// -----------------------------------------------------------------------
const ll maxn = 3010;
ll n, m;
string A[maxn];
ll G[maxn][maxn];
vi D[maxn * 2];
ll dp[maxn][3];
ll calc(vi D) {
ll s = D.size();
memset(dp, 0, sizeof dp);
fori (i, s) {
dp[i + 1][0] = max(dp[i][0], max(dp[i][1], dp[i][2]));
if (D[i] & 1) {
dp[i + 1][1] = max(dp[i][0], dp[i][1]) + 1;
}
if (D[i] & 2) {
dp[i + 1][2] = max(dp[i][0], dp[i][2]) + 1;
}
}
return max(dp[s][0], max(dp[s][1], dp[s][2]));
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n >> m;
A[0] = A[n + 1] = string(m + 2, '.');
fori (i, n) {
cin >> A[i + 1];
A[i + 1] = '.' + A[i + 1] + '.';
}
forifrom (i, 1, n + 1) {
forifrom (j, 1, m + 1) {
if (A[i][j] == 'G') {
if (A[i][j - 1] == 'R' && A[i][j + 1] == 'W') G[i][j] ^= 1;
if (A[i - 1][j] == 'R' && A[i + 1][j] == 'W') G[i][j] ^= 2;
}
}
}
forifrom (i, 1, n + 1) {
forifrom (j, 1, m + 1) {
D[i + j - 2].eb(G[i][j]);
}
}
ll ans = 0;
fori (i, n + m - 1) {
ans += calc(D[i]);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
640 KB |
Output is correct |
2 |
Correct |
1 ms |
640 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
584 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
640 KB |
Output is correct |
2 |
Correct |
1 ms |
640 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
584 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
768 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
640 KB |
Output is correct |
22 |
Correct |
1 ms |
640 KB |
Output is correct |
23 |
Correct |
1 ms |
640 KB |
Output is correct |
24 |
Correct |
1 ms |
640 KB |
Output is correct |
25 |
Correct |
1 ms |
640 KB |
Output is correct |
26 |
Correct |
1 ms |
640 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
640 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
1 ms |
640 KB |
Output is correct |
32 |
Correct |
1 ms |
640 KB |
Output is correct |
33 |
Correct |
1 ms |
640 KB |
Output is correct |
34 |
Correct |
1 ms |
640 KB |
Output is correct |
35 |
Correct |
1 ms |
640 KB |
Output is correct |
36 |
Correct |
1 ms |
640 KB |
Output is correct |
37 |
Correct |
1 ms |
640 KB |
Output is correct |
38 |
Correct |
1 ms |
640 KB |
Output is correct |
39 |
Correct |
1 ms |
640 KB |
Output is correct |
40 |
Correct |
1 ms |
640 KB |
Output is correct |
41 |
Correct |
1 ms |
640 KB |
Output is correct |
42 |
Correct |
1 ms |
640 KB |
Output is correct |
43 |
Correct |
1 ms |
640 KB |
Output is correct |
44 |
Correct |
1 ms |
640 KB |
Output is correct |
45 |
Correct |
1 ms |
640 KB |
Output is correct |
46 |
Correct |
1 ms |
640 KB |
Output is correct |
47 |
Correct |
1 ms |
640 KB |
Output is correct |
48 |
Correct |
1 ms |
640 KB |
Output is correct |
49 |
Correct |
1 ms |
640 KB |
Output is correct |
50 |
Correct |
1 ms |
640 KB |
Output is correct |
51 |
Correct |
1 ms |
640 KB |
Output is correct |
52 |
Correct |
1 ms |
640 KB |
Output is correct |
53 |
Correct |
1 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
640 KB |
Output is correct |
2 |
Correct |
1 ms |
640 KB |
Output is correct |
3 |
Correct |
1 ms |
640 KB |
Output is correct |
4 |
Correct |
1 ms |
640 KB |
Output is correct |
5 |
Correct |
1 ms |
640 KB |
Output is correct |
6 |
Correct |
1 ms |
640 KB |
Output is correct |
7 |
Correct |
1 ms |
640 KB |
Output is correct |
8 |
Correct |
1 ms |
584 KB |
Output is correct |
9 |
Correct |
1 ms |
640 KB |
Output is correct |
10 |
Correct |
1 ms |
640 KB |
Output is correct |
11 |
Correct |
1 ms |
640 KB |
Output is correct |
12 |
Correct |
1 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 KB |
Output is correct |
14 |
Correct |
1 ms |
640 KB |
Output is correct |
15 |
Correct |
1 ms |
640 KB |
Output is correct |
16 |
Correct |
1 ms |
640 KB |
Output is correct |
17 |
Correct |
1 ms |
640 KB |
Output is correct |
18 |
Correct |
1 ms |
640 KB |
Output is correct |
19 |
Correct |
1 ms |
768 KB |
Output is correct |
20 |
Correct |
1 ms |
640 KB |
Output is correct |
21 |
Correct |
1 ms |
640 KB |
Output is correct |
22 |
Correct |
1 ms |
640 KB |
Output is correct |
23 |
Correct |
1 ms |
640 KB |
Output is correct |
24 |
Correct |
1 ms |
640 KB |
Output is correct |
25 |
Correct |
1 ms |
640 KB |
Output is correct |
26 |
Correct |
1 ms |
640 KB |
Output is correct |
27 |
Correct |
1 ms |
640 KB |
Output is correct |
28 |
Correct |
1 ms |
640 KB |
Output is correct |
29 |
Correct |
1 ms |
640 KB |
Output is correct |
30 |
Correct |
1 ms |
640 KB |
Output is correct |
31 |
Correct |
1 ms |
640 KB |
Output is correct |
32 |
Correct |
1 ms |
640 KB |
Output is correct |
33 |
Correct |
1 ms |
640 KB |
Output is correct |
34 |
Correct |
1 ms |
640 KB |
Output is correct |
35 |
Correct |
1 ms |
640 KB |
Output is correct |
36 |
Correct |
1 ms |
640 KB |
Output is correct |
37 |
Correct |
1 ms |
640 KB |
Output is correct |
38 |
Correct |
1 ms |
640 KB |
Output is correct |
39 |
Correct |
1 ms |
640 KB |
Output is correct |
40 |
Correct |
1 ms |
640 KB |
Output is correct |
41 |
Correct |
1 ms |
640 KB |
Output is correct |
42 |
Correct |
1 ms |
640 KB |
Output is correct |
43 |
Correct |
1 ms |
640 KB |
Output is correct |
44 |
Correct |
1 ms |
640 KB |
Output is correct |
45 |
Correct |
1 ms |
640 KB |
Output is correct |
46 |
Correct |
1 ms |
640 KB |
Output is correct |
47 |
Correct |
1 ms |
640 KB |
Output is correct |
48 |
Correct |
1 ms |
640 KB |
Output is correct |
49 |
Correct |
1 ms |
640 KB |
Output is correct |
50 |
Correct |
1 ms |
640 KB |
Output is correct |
51 |
Correct |
1 ms |
640 KB |
Output is correct |
52 |
Correct |
1 ms |
640 KB |
Output is correct |
53 |
Correct |
1 ms |
640 KB |
Output is correct |
54 |
Correct |
5 ms |
768 KB |
Output is correct |
55 |
Correct |
7 ms |
1152 KB |
Output is correct |
56 |
Correct |
5 ms |
896 KB |
Output is correct |
57 |
Correct |
8 ms |
7808 KB |
Output is correct |
58 |
Correct |
35 ms |
16760 KB |
Output is correct |
59 |
Correct |
318 ms |
109688 KB |
Output is correct |
60 |
Correct |
310 ms |
109576 KB |
Output is correct |
61 |
Correct |
343 ms |
109560 KB |
Output is correct |
62 |
Correct |
5 ms |
768 KB |
Output is correct |
63 |
Correct |
294 ms |
107384 KB |
Output is correct |
64 |
Correct |
258 ms |
109560 KB |
Output is correct |
65 |
Correct |
248 ms |
109620 KB |
Output is correct |
66 |
Correct |
246 ms |
109688 KB |
Output is correct |
67 |
Correct |
235 ms |
90064 KB |
Output is correct |
68 |
Correct |
236 ms |
90104 KB |
Output is correct |
69 |
Correct |
240 ms |
95864 KB |
Output is correct |
70 |
Correct |
28 ms |
16836 KB |
Output is correct |
71 |
Correct |
28 ms |
16768 KB |
Output is correct |
72 |
Correct |
28 ms |
16768 KB |
Output is correct |
73 |
Correct |
28 ms |
16768 KB |
Output is correct |
74 |
Correct |
29 ms |
16888 KB |
Output is correct |
75 |
Correct |
28 ms |
16768 KB |
Output is correct |
76 |
Correct |
33 ms |
16768 KB |
Output is correct |
77 |
Correct |
28 ms |
16768 KB |
Output is correct |
78 |
Correct |
27 ms |
16760 KB |
Output is correct |
79 |
Correct |
28 ms |
16768 KB |
Output is correct |
80 |
Correct |
28 ms |
16768 KB |
Output is correct |
81 |
Correct |
27 ms |
16856 KB |
Output is correct |
82 |
Correct |
28 ms |
16768 KB |
Output is correct |
83 |
Correct |
28 ms |
16768 KB |
Output is correct |
84 |
Correct |
30 ms |
16852 KB |
Output is correct |
85 |
Correct |
36 ms |
16768 KB |
Output is correct |
86 |
Correct |
28 ms |
16768 KB |
Output is correct |
87 |
Correct |
28 ms |
16768 KB |
Output is correct |
88 |
Correct |
27 ms |
16768 KB |
Output is correct |
89 |
Correct |
29 ms |
16768 KB |
Output is correct |
90 |
Correct |
27 ms |
16768 KB |
Output is correct |