#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 3005;
int N, M;
string c[MX];
int h[MX][MX], v[MX][MX];
vector<int> g[MX * MX];
int col[MX * MX];
int w = 0, b = 0;
void dfs(int v) {
if(col[v]) b++;
else w++;
for(auto u : g[v]) {
if(col[u] == 2) {
col[u] = col[v] ^ 1;
dfs(u);
} else {
assert(col[u] == (col[v] ^ 1));
}
}
}
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
for(int i = 0; i < MX * MX; i++) col[i] = 2;
cin >> N >> M;
for(int i = 0; i < N; i++) {
cin >> c[i];
}
// build hori
int cnt = 0;
for(int i = 0; i < N; i++) {
for(int j = 0; j + 2 < M; j++) {
if(c[i][j] == 'R' && c[i][j + 1] == 'G' && c[i][j + 2] == 'W') {
cnt++;
assert(h[i][j] == h[i][j + 1] == h[i][j + 2] == 0);
h[i][j] = h[i][j + 1] = h[i][j + 2] = cnt;
j += 2;
}
}
}
// build vert
for(int j = 0; j < M; j++) {
for(int i = 0; i + 2 < N; i++) {
if(c[i][j] == 'R' && c[i + 1][j] == 'G' && c[i + 2][j] == 'W') {
cnt++;
assert(v[i][j] == v[i + 1][j] == v[i + 2][j] == 0);
v[i][j] = v[i + 1][j] = v[i + 2][j] = cnt;
i += 2;
}
}
}
for(int i = 0; i < N; i++) {
for(int j = 0; j < M; j++) {
if(h[i][j] && v[i][j]) {
g[h[i][j]].push_back(v[i][j]);
g[v[i][j]].push_back(h[i][j]);
}
}
}
assert(cnt <= N * M);
// traverse graph
int ans = 0;
for(int i = 1; i <= cnt; i++) {
if(col[i] == 2) {
col[i] = 0;
w = 0, b = 0;
dfs(i);
ans += max(w, b);
}
}
vector<string> v =
{
"RGWRWWRGWR",
"GWRGWRGWRG",
"WRGRRGWRGW",
"RGWRGWRGRR",
"GWRGWRGWRG",
"WRGWRGWRGW",
"RGGRGWGGWR",
"GWRGWRGWRG",
"RRGRWGWWGW",
"RGWRGWRGWR"
};
bool is = 1;
for(int i = 0; i < N; i++) {
is &= v[i] == c[i];
}
if(is) {
assert(ans == 22);
}
cout << ans << '\n';
}
Compilation message
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from dango_maker.cpp:1:
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:45:40: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
45 | assert(h[i][j] == h[i][j + 1] == h[i][j + 2] == 0);
| ~~~~~~~~^~~~~~~~~~~~~~
dango_maker.cpp:45:55: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
45 | assert(h[i][j] == h[i][j + 1] == h[i][j + 2] == 0);
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
dango_maker.cpp:57:40: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
57 | assert(v[i][j] == v[i + 1][j] == v[i + 2][j] == 0);
| ~~~~~~~~^~~~~~~~~~~~~~
dango_maker.cpp:57:55: warning: suggest parentheses around comparison in operand of '==' [-Wparentheses]
57 | assert(v[i][j] == v[i + 1][j] == v[i + 2][j] == 0);
| ~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
247852 KB |
Output is correct |
2 |
Correct |
122 ms |
247804 KB |
Output is correct |
3 |
Correct |
125 ms |
247732 KB |
Output is correct |
4 |
Correct |
141 ms |
247752 KB |
Output is correct |
5 |
Correct |
121 ms |
247884 KB |
Output is correct |
6 |
Correct |
129 ms |
247704 KB |
Output is correct |
7 |
Correct |
127 ms |
247828 KB |
Output is correct |
8 |
Correct |
124 ms |
247756 KB |
Output is correct |
9 |
Correct |
137 ms |
247796 KB |
Output is correct |
10 |
Correct |
127 ms |
247756 KB |
Output is correct |
11 |
Correct |
126 ms |
247836 KB |
Output is correct |
12 |
Correct |
126 ms |
247744 KB |
Output is correct |
13 |
Correct |
127 ms |
247704 KB |
Output is correct |
14 |
Correct |
127 ms |
247800 KB |
Output is correct |
15 |
Correct |
129 ms |
247792 KB |
Output is correct |
16 |
Correct |
127 ms |
247800 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
247852 KB |
Output is correct |
2 |
Correct |
122 ms |
247804 KB |
Output is correct |
3 |
Correct |
125 ms |
247732 KB |
Output is correct |
4 |
Correct |
141 ms |
247752 KB |
Output is correct |
5 |
Correct |
121 ms |
247884 KB |
Output is correct |
6 |
Correct |
129 ms |
247704 KB |
Output is correct |
7 |
Correct |
127 ms |
247828 KB |
Output is correct |
8 |
Correct |
124 ms |
247756 KB |
Output is correct |
9 |
Correct |
137 ms |
247796 KB |
Output is correct |
10 |
Correct |
127 ms |
247756 KB |
Output is correct |
11 |
Correct |
126 ms |
247836 KB |
Output is correct |
12 |
Correct |
126 ms |
247744 KB |
Output is correct |
13 |
Correct |
127 ms |
247704 KB |
Output is correct |
14 |
Correct |
127 ms |
247800 KB |
Output is correct |
15 |
Correct |
129 ms |
247792 KB |
Output is correct |
16 |
Correct |
127 ms |
247800 KB |
Output is correct |
17 |
Correct |
125 ms |
247708 KB |
Output is correct |
18 |
Correct |
141 ms |
247992 KB |
Output is correct |
19 |
Correct |
129 ms |
247764 KB |
Output is correct |
20 |
Correct |
138 ms |
247756 KB |
Output is correct |
21 |
Correct |
127 ms |
247868 KB |
Output is correct |
22 |
Correct |
128 ms |
247756 KB |
Output is correct |
23 |
Correct |
126 ms |
247936 KB |
Output is correct |
24 |
Correct |
126 ms |
247748 KB |
Output is correct |
25 |
Correct |
126 ms |
247728 KB |
Output is correct |
26 |
Correct |
138 ms |
247748 KB |
Output is correct |
27 |
Correct |
130 ms |
247988 KB |
Output is correct |
28 |
Correct |
125 ms |
247860 KB |
Output is correct |
29 |
Correct |
130 ms |
247824 KB |
Output is correct |
30 |
Correct |
127 ms |
247792 KB |
Output is correct |
31 |
Correct |
128 ms |
247912 KB |
Output is correct |
32 |
Correct |
126 ms |
247844 KB |
Output is correct |
33 |
Correct |
130 ms |
247884 KB |
Output is correct |
34 |
Incorrect |
127 ms |
247832 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
247852 KB |
Output is correct |
2 |
Correct |
122 ms |
247804 KB |
Output is correct |
3 |
Correct |
125 ms |
247732 KB |
Output is correct |
4 |
Correct |
141 ms |
247752 KB |
Output is correct |
5 |
Correct |
121 ms |
247884 KB |
Output is correct |
6 |
Correct |
129 ms |
247704 KB |
Output is correct |
7 |
Correct |
127 ms |
247828 KB |
Output is correct |
8 |
Correct |
124 ms |
247756 KB |
Output is correct |
9 |
Correct |
137 ms |
247796 KB |
Output is correct |
10 |
Correct |
127 ms |
247756 KB |
Output is correct |
11 |
Correct |
126 ms |
247836 KB |
Output is correct |
12 |
Correct |
126 ms |
247744 KB |
Output is correct |
13 |
Correct |
127 ms |
247704 KB |
Output is correct |
14 |
Correct |
127 ms |
247800 KB |
Output is correct |
15 |
Correct |
129 ms |
247792 KB |
Output is correct |
16 |
Correct |
127 ms |
247800 KB |
Output is correct |
17 |
Correct |
125 ms |
247708 KB |
Output is correct |
18 |
Correct |
141 ms |
247992 KB |
Output is correct |
19 |
Correct |
129 ms |
247764 KB |
Output is correct |
20 |
Correct |
138 ms |
247756 KB |
Output is correct |
21 |
Correct |
127 ms |
247868 KB |
Output is correct |
22 |
Correct |
128 ms |
247756 KB |
Output is correct |
23 |
Correct |
126 ms |
247936 KB |
Output is correct |
24 |
Correct |
126 ms |
247748 KB |
Output is correct |
25 |
Correct |
126 ms |
247728 KB |
Output is correct |
26 |
Correct |
138 ms |
247748 KB |
Output is correct |
27 |
Correct |
130 ms |
247988 KB |
Output is correct |
28 |
Correct |
125 ms |
247860 KB |
Output is correct |
29 |
Correct |
130 ms |
247824 KB |
Output is correct |
30 |
Correct |
127 ms |
247792 KB |
Output is correct |
31 |
Correct |
128 ms |
247912 KB |
Output is correct |
32 |
Correct |
126 ms |
247844 KB |
Output is correct |
33 |
Correct |
130 ms |
247884 KB |
Output is correct |
34 |
Incorrect |
127 ms |
247832 KB |
Output isn't correct |
35 |
Halted |
0 ms |
0 KB |
- |