/* Author : Mychecksdead */
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
const int N = 1E7+100, M = 1e5+10, K = 20;
int n, m;
string s[4000];
bitset<3> g[N][2];
bitset<N> v[2];
bitset<N> vis[2];
vector<vector<int>> arr;
int aa[3] = {1, 2, 0};
pair<int, int> dfs(int x, int p){
pair<int, int> ans = {1, 0};
vis[p][x] = 1;
for(int k = 0; k < 3; ++k){
int y = aa[k];
if(!g[x][p][y]) continue;
pair<int, int> u = {arr[p][y]+x, 1-p};
if(vis[u.second][u.first]) continue;
auto dp = dfs(u.first, u.second);
ans.first += dp.second;
ans.second += max(dp.first, dp.second);
}
// cout <<x/m << ' ' << x%m << ' ' << p << ' ' << ans.first << ' ' << ans.second << '\n';
return ans;
}
void solve(){
cin >> n >> m;
arr = {
{
0,
m-1,
2*m-2
},
{
0,
-m+1,
-2*m+2
}
};
for(int i = 0; i < n; ++i) cin >> s[i];
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
if(i < n - 2){
int x = i*m+j;
if(s[i][j] == 'R' && s[i+1][j] == 'G' && s[i+2][j] == 'W'){
if(v[1][x]) g[x][0][0] = 1, g[x][1][0] = 1;
if(v[1][x+m]) g[x][0][1] = 1, g[x+m-1][1][1] = 1;
if(v[1][x+m+m]) g[x][0][2] = 1, g[x+2*m-2][1][2] = 1;
v[0][x] = v[0][x+m] = v[0][x+m+m] = 1;
}
}
if(j < m-2){
int x = i*m+j;
if(s[i][j] == 'R' && s[i][j+1] == 'G' && s[i][j+2] == 'W'){
if(v[0][x]) g[x][1][0] = 1, g[x][0][0] = 1;
if(v[0][x+1]) g[x][1][1] = 1, g[x+1-m][0][1] = 1;
if(v[0][x+2]) g[x][1][2] = 1, g[x+2-2*m][0][2] = 1;
v[1][x] = v[1][x+1] = v[1][x+2] = 1;
}
}
}
}
int ans = 0;
for(int i = 0; i < n; ++i){
for(int j = 0; j < m; ++j){
if(s[i][j] != 'R') continue;
if(!vis[1][i*m+j] && v[1][i*m+j]){
auto dp = dfs(i*m+j, 1);
ans += max(dp.first, dp.second);
// cout << i << ' ' << j << ' '<< ' ' << 0 << ' ' << ans << '\n';
}else if(!vis[0][i*m+j] && v[0][i*m+j]){
auto dp = dfs(i*m+j, 0);
ans += max(dp.first, dp.second);
// cout << i << ' ' << j << ' '<< ' ' << 1 << ' ' << ans << '\n';
}
}
}
cout << ans;
}
int main(){
cin.tie(0); ios::sync_with_stdio(0);
int T = 1, aa;
// cin >> T;aa=T;
while(T--){
// cout << "Case #" << aa-T << ": ";
solve();
}
return 0;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:98:14: warning: unused variable 'aa' [-Wunused-variable]
98 | int T = 1, aa;
| ^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
0 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 |
0 ms |
468 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 |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
0 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
0 ms |
468 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 |
468 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 |
456 KB |
Output is correct |
40 |
Correct |
1 ms |
456 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
372 KB |
Output is correct |
45 |
Correct |
1 ms |
456 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
456 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
460 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
456 KB |
Output is correct |
53 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Correct |
0 ms |
468 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
0 ms |
468 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
468 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
1 ms |
468 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
0 ms |
468 KB |
Output is correct |
18 |
Correct |
1 ms |
468 KB |
Output is correct |
19 |
Correct |
0 ms |
468 KB |
Output is correct |
20 |
Correct |
0 ms |
468 KB |
Output is correct |
21 |
Correct |
0 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 |
0 ms |
468 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 |
0 ms |
468 KB |
Output is correct |
29 |
Correct |
1 ms |
468 KB |
Output is correct |
30 |
Correct |
0 ms |
468 KB |
Output is correct |
31 |
Correct |
1 ms |
468 KB |
Output is correct |
32 |
Correct |
0 ms |
468 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 |
468 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 |
456 KB |
Output is correct |
40 |
Correct |
1 ms |
456 KB |
Output is correct |
41 |
Correct |
1 ms |
468 KB |
Output is correct |
42 |
Correct |
1 ms |
468 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
372 KB |
Output is correct |
45 |
Correct |
1 ms |
456 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
456 KB |
Output is correct |
49 |
Correct |
1 ms |
468 KB |
Output is correct |
50 |
Correct |
1 ms |
460 KB |
Output is correct |
51 |
Correct |
1 ms |
468 KB |
Output is correct |
52 |
Correct |
1 ms |
456 KB |
Output is correct |
53 |
Correct |
1 ms |
468 KB |
Output is correct |
54 |
Correct |
1 ms |
468 KB |
Output is correct |
55 |
Correct |
1 ms |
468 KB |
Output is correct |
56 |
Correct |
1 ms |
724 KB |
Output is correct |
57 |
Correct |
1 ms |
724 KB |
Output is correct |
58 |
Correct |
27 ms |
18700 KB |
Output is correct |
59 |
Correct |
219 ms |
163156 KB |
Output is correct |
60 |
Correct |
196 ms |
163248 KB |
Output is correct |
61 |
Correct |
205 ms |
163052 KB |
Output is correct |
62 |
Correct |
1 ms |
468 KB |
Output is correct |
63 |
Correct |
188 ms |
157544 KB |
Output is correct |
64 |
Correct |
280 ms |
164768 KB |
Output is correct |
65 |
Correct |
298 ms |
164936 KB |
Output is correct |
66 |
Correct |
360 ms |
164852 KB |
Output is correct |
67 |
Correct |
67 ms |
21408 KB |
Output is correct |
68 |
Correct |
97 ms |
21760 KB |
Output is correct |
69 |
Correct |
77 ms |
40140 KB |
Output is correct |
70 |
Correct |
36 ms |
18768 KB |
Output is correct |
71 |
Correct |
24 ms |
18748 KB |
Output is correct |
72 |
Correct |
23 ms |
18840 KB |
Output is correct |
73 |
Correct |
33 ms |
18840 KB |
Output is correct |
74 |
Correct |
25 ms |
18832 KB |
Output is correct |
75 |
Correct |
26 ms |
18776 KB |
Output is correct |
76 |
Correct |
36 ms |
18768 KB |
Output is correct |
77 |
Correct |
29 ms |
18832 KB |
Output is correct |
78 |
Correct |
31 ms |
18828 KB |
Output is correct |
79 |
Correct |
27 ms |
18756 KB |
Output is correct |
80 |
Correct |
27 ms |
18776 KB |
Output is correct |
81 |
Correct |
35 ms |
18776 KB |
Output is correct |
82 |
Correct |
27 ms |
18804 KB |
Output is correct |
83 |
Correct |
27 ms |
18836 KB |
Output is correct |
84 |
Correct |
36 ms |
18820 KB |
Output is correct |
85 |
Correct |
31 ms |
18740 KB |
Output is correct |
86 |
Correct |
32 ms |
18736 KB |
Output is correct |
87 |
Correct |
35 ms |
18836 KB |
Output is correct |
88 |
Correct |
31 ms |
18832 KB |
Output is correct |
89 |
Correct |
37 ms |
18832 KB |
Output is correct |
90 |
Correct |
37 ms |
18752 KB |
Output is correct |