#include <iostream>
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll maxn = 2*1e5+5, INF = 1e9+9;
void solve(){
int n, m;
cin >> n >> m;
vector<string> s(n+1);
for(int i = 1; i <= n; i++){
cin >> s[i];
s[i] = ' ' + s[i];
}
vector<vector<bool>> ud(n+1, vector<bool>(m+1, 0)), lr(n+1, vector<bool>(m+1, 0));
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
if(i > 1 && i < n){
if(s[i-1][j] == 'R' && s[i][j] == 'G' && s[i+1][j] == 'W'){
ud[i][j] = 1;
}
}
if(j > 1 && j < m){
if(s[i][j-1] == 'R' && s[i][j] == 'G' && s[i][j+1] == 'W'){
lr[i][j] = 1;
}
}
}
}
auto chmax = [&](int &a, int b) -> void{
a = max(a, b);
};
int ans = 0;
for(int sum = 2; sum < n+m; sum++){
vector<pair<int, int>> items;
for(int i = 1; i <= n; i++){
int j = sum-i;
if(j < 1 || j > m) continue;
items.push_back({ud[i][j], lr[i][j]});
}
vector<int> f(3, -INF), prv(3, -INF);
f[0] = 0;
for(auto it : items){
prv = f;
fill(f.begin(), f.end(), -INF);
chmax(f[0], max({prv[0], prv[1], prv[2]}));
if(it.first) chmax(f[1], max(prv[0], prv[1])+1);
if(it.second) chmax(f[2], max(prv[0], prv[2])+1);
}
int res = 0;
for(int j = 0; j <= 2; j++) chmax(res, f[j]);
ans += res;
}
cout << ans;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
504 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
500 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
504 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
504 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
504 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Correct |
1 ms |
336 KB |
Output is correct |
8 |
Correct |
1 ms |
508 KB |
Output is correct |
9 |
Correct |
1 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Correct |
1 ms |
336 KB |
Output is correct |
13 |
Correct |
1 ms |
504 KB |
Output is correct |
14 |
Correct |
1 ms |
336 KB |
Output is correct |
15 |
Correct |
2 ms |
336 KB |
Output is correct |
16 |
Correct |
1 ms |
336 KB |
Output is correct |
17 |
Correct |
1 ms |
336 KB |
Output is correct |
18 |
Correct |
1 ms |
336 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
1 ms |
504 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
2 ms |
336 KB |
Output is correct |
24 |
Correct |
1 ms |
336 KB |
Output is correct |
25 |
Correct |
1 ms |
336 KB |
Output is correct |
26 |
Correct |
1 ms |
336 KB |
Output is correct |
27 |
Correct |
1 ms |
336 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
336 KB |
Output is correct |
30 |
Correct |
1 ms |
336 KB |
Output is correct |
31 |
Correct |
1 ms |
336 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
336 KB |
Output is correct |
34 |
Correct |
1 ms |
336 KB |
Output is correct |
35 |
Correct |
1 ms |
336 KB |
Output is correct |
36 |
Correct |
1 ms |
336 KB |
Output is correct |
37 |
Correct |
1 ms |
336 KB |
Output is correct |
38 |
Correct |
1 ms |
336 KB |
Output is correct |
39 |
Correct |
1 ms |
500 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
1 ms |
504 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
336 KB |
Output is correct |
44 |
Correct |
1 ms |
336 KB |
Output is correct |
45 |
Correct |
1 ms |
336 KB |
Output is correct |
46 |
Correct |
1 ms |
336 KB |
Output is correct |
47 |
Correct |
1 ms |
336 KB |
Output is correct |
48 |
Correct |
1 ms |
504 KB |
Output is correct |
49 |
Correct |
1 ms |
336 KB |
Output is correct |
50 |
Correct |
1 ms |
336 KB |
Output is correct |
51 |
Correct |
1 ms |
336 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
336 KB |
Output is correct |
54 |
Correct |
1 ms |
336 KB |
Output is correct |
55 |
Correct |
8 ms |
848 KB |
Output is correct |
56 |
Correct |
2 ms |
500 KB |
Output is correct |
57 |
Correct |
5 ms |
592 KB |
Output is correct |
58 |
Correct |
33 ms |
1896 KB |
Output is correct |
59 |
Correct |
290 ms |
11856 KB |
Output is correct |
60 |
Correct |
294 ms |
11952 KB |
Output is correct |
61 |
Correct |
289 ms |
11976 KB |
Output is correct |
62 |
Correct |
1 ms |
336 KB |
Output is correct |
63 |
Correct |
282 ms |
11596 KB |
Output is correct |
64 |
Correct |
223 ms |
16580 KB |
Output is correct |
65 |
Correct |
217 ms |
11780 KB |
Output is correct |
66 |
Correct |
214 ms |
11948 KB |
Output is correct |
67 |
Correct |
208 ms |
11812 KB |
Output is correct |
68 |
Correct |
211 ms |
12112 KB |
Output is correct |
69 |
Correct |
233 ms |
16448 KB |
Output is correct |
70 |
Correct |
24 ms |
1872 KB |
Output is correct |
71 |
Correct |
25 ms |
1872 KB |
Output is correct |
72 |
Correct |
24 ms |
1872 KB |
Output is correct |
73 |
Correct |
25 ms |
1872 KB |
Output is correct |
74 |
Correct |
26 ms |
2640 KB |
Output is correct |
75 |
Correct |
24 ms |
1872 KB |
Output is correct |
76 |
Correct |
24 ms |
1872 KB |
Output is correct |
77 |
Correct |
23 ms |
1872 KB |
Output is correct |
78 |
Correct |
25 ms |
2656 KB |
Output is correct |
79 |
Correct |
25 ms |
1872 KB |
Output is correct |
80 |
Correct |
24 ms |
1872 KB |
Output is correct |
81 |
Correct |
24 ms |
2044 KB |
Output is correct |
82 |
Correct |
23 ms |
1872 KB |
Output is correct |
83 |
Correct |
23 ms |
1872 KB |
Output is correct |
84 |
Correct |
23 ms |
1872 KB |
Output is correct |
85 |
Correct |
23 ms |
1872 KB |
Output is correct |
86 |
Correct |
24 ms |
1872 KB |
Output is correct |
87 |
Correct |
25 ms |
2640 KB |
Output is correct |
88 |
Correct |
27 ms |
1872 KB |
Output is correct |
89 |
Correct |
25 ms |
2640 KB |
Output is correct |
90 |
Correct |
23 ms |
1900 KB |
Output is correct |