#include <bits/stdc++.h>
using namespace std;
#define sp " "
#define endl "\n";
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define pb push_back
#define pii pair<int, int>
#define st first
#define nd second
#define N 3005
const int modulo = 1e9 + 7;
char arr[N][N];
int dp[N * 2][N][2][2];
int ho[N][N], ver[N][N];
int32_t main()
{
fastio();
int n, m;
cin>>n>>m;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
cin>>arr[i][j];
}
}
for (int i = 1; i <= n; i++)
for (int j = 1; j <= m - 2; j++)
if (arr[i][j] == 'R' && arr[i][j + 1] == 'G' && arr[i][j + 2] == 'W') ho[i][j] = 1;
for (int i = 1; i <= n - 2; i++)
for (int j = 1; j <= m; j++)
if (arr[i][j] == 'R' && arr[i + 1][j] == 'G' && arr[i + 2][j] == 'W') ver[i][j] = 1;
int ans = 0;
for (int i = 1; i <= n + m; i++)
{
int lw = max((int)1, i - n);
int up = min(i - 1, m);
for (int j = up; j >= lw; j--)
{
for (int k = 0; k < 2; k++)
{
for (int l = 0; l < 2; l++)
{
int t1 = dp[i][j + 1][0][k], t2 = 0, t3 = 0;
if (ho[i - j][j]) t2 = dp[i][j + 1][1][k] + 1;
if (ver[i - j][j] && (k | l) == 0) t3 = dp[i][j + 1][0][k] + 1;
dp[i][j][k][l] = max(t1, max(t2, t3));
}
}
}
//cout<<i<<sp<<lw<<sp<<up<<" :"<<dp[i][lw][0][0]<<endl;
ans += dp[i][lw][0][0];
}
cout<<ans<<endl;
cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " seconds\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
408 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
0 ms |
468 KB |
Output is correct |
41 |
Correct |
0 ms |
468 KB |
Output is correct |
42 |
Correct |
0 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Correct |
0 ms |
468 KB |
Output is correct |
50 |
Correct |
0 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
0 ms |
468 KB |
Output is correct |
53 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
1 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
468 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
1 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
468 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
408 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
1 ms |
468 KB |
Output is correct |
39 |
Correct |
1 ms |
468 KB |
Output is correct |
40 |
Correct |
0 ms |
468 KB |
Output is correct |
41 |
Correct |
0 ms |
468 KB |
Output is correct |
42 |
Correct |
0 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
468 KB |
Output is correct |
48 |
Correct |
1 ms |
468 KB |
Output is correct |
49 |
Correct |
0 ms |
468 KB |
Output is correct |
50 |
Correct |
0 ms |
468 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
0 ms |
468 KB |
Output is correct |
53 |
Correct |
1 ms |
468 KB |
Output is correct |
54 |
Correct |
7 ms |
12600 KB |
Output is correct |
55 |
Correct |
15 ms |
21972 KB |
Output is correct |
56 |
Correct |
8 ms |
12900 KB |
Output is correct |
57 |
Correct |
13 ms |
24584 KB |
Output is correct |
58 |
Correct |
58 ms |
42428 KB |
Output is correct |
59 |
Correct |
460 ms |
252452 KB |
Output is correct |
60 |
Correct |
504 ms |
252748 KB |
Output is correct |
61 |
Correct |
477 ms |
252524 KB |
Output is correct |
62 |
Correct |
8 ms |
11860 KB |
Output is correct |
63 |
Correct |
454 ms |
247564 KB |
Output is correct |
64 |
Correct |
411 ms |
252544 KB |
Output is correct |
65 |
Correct |
394 ms |
252576 KB |
Output is correct |
66 |
Correct |
392 ms |
252568 KB |
Output is correct |
67 |
Correct |
333 ms |
197852 KB |
Output is correct |
68 |
Correct |
323 ms |
197936 KB |
Output is correct |
69 |
Correct |
357 ms |
207800 KB |
Output is correct |
70 |
Correct |
50 ms |
43704 KB |
Output is correct |
71 |
Correct |
50 ms |
43740 KB |
Output is correct |
72 |
Correct |
44 ms |
43720 KB |
Output is correct |
73 |
Correct |
44 ms |
43724 KB |
Output is correct |
74 |
Correct |
49 ms |
43732 KB |
Output is correct |
75 |
Correct |
46 ms |
43768 KB |
Output is correct |
76 |
Correct |
48 ms |
43732 KB |
Output is correct |
77 |
Correct |
56 ms |
43824 KB |
Output is correct |
78 |
Correct |
48 ms |
43728 KB |
Output is correct |
79 |
Correct |
47 ms |
43744 KB |
Output is correct |
80 |
Correct |
45 ms |
43728 KB |
Output is correct |
81 |
Correct |
48 ms |
43896 KB |
Output is correct |
82 |
Correct |
44 ms |
43768 KB |
Output is correct |
83 |
Correct |
44 ms |
43724 KB |
Output is correct |
84 |
Correct |
46 ms |
43720 KB |
Output is correct |
85 |
Correct |
46 ms |
43756 KB |
Output is correct |
86 |
Correct |
56 ms |
43772 KB |
Output is correct |
87 |
Correct |
47 ms |
43748 KB |
Output is correct |
88 |
Correct |
54 ms |
43736 KB |
Output is correct |
89 |
Correct |
45 ms |
43812 KB |
Output is correct |
90 |
Correct |
47 ms |
43724 KB |
Output is correct |