#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T>
bool chmax(T &a, T b) { return a < b ? (a = b, true) : false; }
template<class T>
bool chmin(T &a, T b) { return b < a ? (a = b, true) : false; }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U>
void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T>
void debug(T L, T R) { while (L != R) cerr << *L << " \n"[next(L) == R], ++L; }
#else
#define DE(...) 0
#define debug(...) 0
#endif
const int MAX_N = 3005, MAX_M = MAX_N * MAX_N / 3 << 1;
char w[MAX_N][MAX_N];
int n, m, a, b, id[MAX_N][MAX_N];
bool valid (char a, char b, char c) { return a == 'R' && b == 'G' && c == 'W'; }
array<int,3> edge[MAX_M];
int ma[MAX_M], vist[MAX_M], deg[MAX_M], lst[MAX_M];
int Time;
void expand(int x, int y) {
while (true) {
int u = ma[x];
ma[x] = y, ma[y] = x;
if (u == -1) return;
y = u, x = lst[y];
}
}
bool dfs(int x) {
queue<int> q;
q.push(x);
vist[x] = Time;
lst[x] = 0;
while (q.size()) {
int x = q.front(); q.pop();
for (int i = 0;i < deg[x];++i) {
int u = edge[x][i];
if (ma[u] == -1)
return expand(x, u), true;
lst[u] = x;
if (exchange(vist[u], Time) != Time)
q.emplace(ma[u]);
}
}
return false;
}
int max_clique() {
b += a;
memset(ma, -1, sizeof(ma));
int res = b;
for (int i = 1;i <= a;++i)
if (ma[i] == -1 && (Time = i, dfs(i)))
--res;
return res;
}
int solve() {
for (int i = 1;i <= n;++i)
for (int j = 1;j <= m;++j) {
if (valid(w[i][j-1], w[i][j], w[i][j+1]))
id[i][j] = ++a;
}
for (int i = 1;i <= n;++i)
for (int j = 1;j <= m;++j) {
if (valid(w[i-1][j], w[i][j], w[i+1][j])) {
++b;
for (int x : {id[i-1][j+1], id[i][j], id[i+1][j-1]}) if (x) {
edge[x][ deg[x]++ ] = b + a;
}
}
}
return max_clique();
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= n;++i)
cin >> w[i] + 1;
cout << solve() << '\n';
}
Compilation message
dango_maker.cpp: In function 'int32_t main()':
dango_maker.cpp:89:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
89 | cin >> w[i] + 1;
| ~~~~~^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23916 KB |
Output is correct |
2 |
Correct |
18 ms |
23916 KB |
Output is correct |
3 |
Correct |
14 ms |
23916 KB |
Output is correct |
4 |
Correct |
14 ms |
23916 KB |
Output is correct |
5 |
Correct |
14 ms |
23916 KB |
Output is correct |
6 |
Correct |
13 ms |
23916 KB |
Output is correct |
7 |
Correct |
13 ms |
23916 KB |
Output is correct |
8 |
Correct |
14 ms |
23916 KB |
Output is correct |
9 |
Correct |
14 ms |
23916 KB |
Output is correct |
10 |
Correct |
14 ms |
23916 KB |
Output is correct |
11 |
Correct |
13 ms |
23916 KB |
Output is correct |
12 |
Correct |
13 ms |
23916 KB |
Output is correct |
13 |
Correct |
14 ms |
23916 KB |
Output is correct |
14 |
Correct |
15 ms |
23916 KB |
Output is correct |
15 |
Correct |
13 ms |
23916 KB |
Output is correct |
16 |
Correct |
13 ms |
23916 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23916 KB |
Output is correct |
2 |
Correct |
18 ms |
23916 KB |
Output is correct |
3 |
Correct |
14 ms |
23916 KB |
Output is correct |
4 |
Correct |
14 ms |
23916 KB |
Output is correct |
5 |
Correct |
14 ms |
23916 KB |
Output is correct |
6 |
Correct |
13 ms |
23916 KB |
Output is correct |
7 |
Correct |
13 ms |
23916 KB |
Output is correct |
8 |
Correct |
14 ms |
23916 KB |
Output is correct |
9 |
Correct |
14 ms |
23916 KB |
Output is correct |
10 |
Correct |
14 ms |
23916 KB |
Output is correct |
11 |
Correct |
13 ms |
23916 KB |
Output is correct |
12 |
Correct |
13 ms |
23916 KB |
Output is correct |
13 |
Correct |
14 ms |
23916 KB |
Output is correct |
14 |
Correct |
15 ms |
23916 KB |
Output is correct |
15 |
Correct |
13 ms |
23916 KB |
Output is correct |
16 |
Correct |
13 ms |
23916 KB |
Output is correct |
17 |
Correct |
14 ms |
23916 KB |
Output is correct |
18 |
Correct |
14 ms |
23916 KB |
Output is correct |
19 |
Correct |
14 ms |
24044 KB |
Output is correct |
20 |
Correct |
15 ms |
24044 KB |
Output is correct |
21 |
Correct |
14 ms |
24044 KB |
Output is correct |
22 |
Correct |
15 ms |
24044 KB |
Output is correct |
23 |
Correct |
14 ms |
23916 KB |
Output is correct |
24 |
Correct |
15 ms |
23916 KB |
Output is correct |
25 |
Correct |
14 ms |
23916 KB |
Output is correct |
26 |
Correct |
14 ms |
23916 KB |
Output is correct |
27 |
Correct |
13 ms |
24044 KB |
Output is correct |
28 |
Correct |
13 ms |
24044 KB |
Output is correct |
29 |
Correct |
13 ms |
24044 KB |
Output is correct |
30 |
Correct |
16 ms |
23916 KB |
Output is correct |
31 |
Correct |
15 ms |
24044 KB |
Output is correct |
32 |
Correct |
14 ms |
23916 KB |
Output is correct |
33 |
Correct |
14 ms |
24044 KB |
Output is correct |
34 |
Correct |
13 ms |
24044 KB |
Output is correct |
35 |
Correct |
14 ms |
24044 KB |
Output is correct |
36 |
Correct |
16 ms |
24044 KB |
Output is correct |
37 |
Correct |
14 ms |
24044 KB |
Output is correct |
38 |
Correct |
14 ms |
24044 KB |
Output is correct |
39 |
Correct |
15 ms |
24044 KB |
Output is correct |
40 |
Correct |
13 ms |
24044 KB |
Output is correct |
41 |
Correct |
14 ms |
24044 KB |
Output is correct |
42 |
Correct |
14 ms |
24044 KB |
Output is correct |
43 |
Correct |
14 ms |
24044 KB |
Output is correct |
44 |
Correct |
14 ms |
24044 KB |
Output is correct |
45 |
Correct |
14 ms |
24044 KB |
Output is correct |
46 |
Correct |
14 ms |
24064 KB |
Output is correct |
47 |
Correct |
14 ms |
24044 KB |
Output is correct |
48 |
Correct |
14 ms |
24044 KB |
Output is correct |
49 |
Correct |
13 ms |
24044 KB |
Output is correct |
50 |
Correct |
13 ms |
24044 KB |
Output is correct |
51 |
Correct |
15 ms |
24044 KB |
Output is correct |
52 |
Correct |
14 ms |
24044 KB |
Output is correct |
53 |
Correct |
14 ms |
24044 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
23916 KB |
Output is correct |
2 |
Correct |
18 ms |
23916 KB |
Output is correct |
3 |
Correct |
14 ms |
23916 KB |
Output is correct |
4 |
Correct |
14 ms |
23916 KB |
Output is correct |
5 |
Correct |
14 ms |
23916 KB |
Output is correct |
6 |
Correct |
13 ms |
23916 KB |
Output is correct |
7 |
Correct |
13 ms |
23916 KB |
Output is correct |
8 |
Correct |
14 ms |
23916 KB |
Output is correct |
9 |
Correct |
14 ms |
23916 KB |
Output is correct |
10 |
Correct |
14 ms |
23916 KB |
Output is correct |
11 |
Correct |
13 ms |
23916 KB |
Output is correct |
12 |
Correct |
13 ms |
23916 KB |
Output is correct |
13 |
Correct |
14 ms |
23916 KB |
Output is correct |
14 |
Correct |
15 ms |
23916 KB |
Output is correct |
15 |
Correct |
13 ms |
23916 KB |
Output is correct |
16 |
Correct |
13 ms |
23916 KB |
Output is correct |
17 |
Correct |
14 ms |
23916 KB |
Output is correct |
18 |
Correct |
14 ms |
23916 KB |
Output is correct |
19 |
Correct |
14 ms |
24044 KB |
Output is correct |
20 |
Correct |
15 ms |
24044 KB |
Output is correct |
21 |
Correct |
14 ms |
24044 KB |
Output is correct |
22 |
Correct |
15 ms |
24044 KB |
Output is correct |
23 |
Correct |
14 ms |
23916 KB |
Output is correct |
24 |
Correct |
15 ms |
23916 KB |
Output is correct |
25 |
Correct |
14 ms |
23916 KB |
Output is correct |
26 |
Correct |
14 ms |
23916 KB |
Output is correct |
27 |
Correct |
13 ms |
24044 KB |
Output is correct |
28 |
Correct |
13 ms |
24044 KB |
Output is correct |
29 |
Correct |
13 ms |
24044 KB |
Output is correct |
30 |
Correct |
16 ms |
23916 KB |
Output is correct |
31 |
Correct |
15 ms |
24044 KB |
Output is correct |
32 |
Correct |
14 ms |
23916 KB |
Output is correct |
33 |
Correct |
14 ms |
24044 KB |
Output is correct |
34 |
Correct |
13 ms |
24044 KB |
Output is correct |
35 |
Correct |
14 ms |
24044 KB |
Output is correct |
36 |
Correct |
16 ms |
24044 KB |
Output is correct |
37 |
Correct |
14 ms |
24044 KB |
Output is correct |
38 |
Correct |
14 ms |
24044 KB |
Output is correct |
39 |
Correct |
15 ms |
24044 KB |
Output is correct |
40 |
Correct |
13 ms |
24044 KB |
Output is correct |
41 |
Correct |
14 ms |
24044 KB |
Output is correct |
42 |
Correct |
14 ms |
24044 KB |
Output is correct |
43 |
Correct |
14 ms |
24044 KB |
Output is correct |
44 |
Correct |
14 ms |
24044 KB |
Output is correct |
45 |
Correct |
14 ms |
24044 KB |
Output is correct |
46 |
Correct |
14 ms |
24064 KB |
Output is correct |
47 |
Correct |
14 ms |
24044 KB |
Output is correct |
48 |
Correct |
14 ms |
24044 KB |
Output is correct |
49 |
Correct |
13 ms |
24044 KB |
Output is correct |
50 |
Correct |
13 ms |
24044 KB |
Output is correct |
51 |
Correct |
15 ms |
24044 KB |
Output is correct |
52 |
Correct |
14 ms |
24044 KB |
Output is correct |
53 |
Correct |
14 ms |
24044 KB |
Output is correct |
54 |
Correct |
14 ms |
23916 KB |
Output is correct |
55 |
Correct |
19 ms |
32748 KB |
Output is correct |
56 |
Correct |
14 ms |
24044 KB |
Output is correct |
57 |
Correct |
20 ms |
34924 KB |
Output is correct |
58 |
Correct |
30 ms |
36972 KB |
Output is correct |
59 |
Correct |
117 ms |
83840 KB |
Output is correct |
60 |
Correct |
121 ms |
83820 KB |
Output is correct |
61 |
Correct |
124 ms |
83820 KB |
Output is correct |
62 |
Correct |
14 ms |
23916 KB |
Output is correct |
63 |
Correct |
115 ms |
83692 KB |
Output is correct |
64 |
Correct |
403 ms |
166636 KB |
Output is correct |
65 |
Correct |
447 ms |
168428 KB |
Output is correct |
66 |
Correct |
501 ms |
168300 KB |
Output is correct |
67 |
Correct |
65 ms |
39404 KB |
Output is correct |
68 |
Correct |
65 ms |
39532 KB |
Output is correct |
69 |
Correct |
72 ms |
49260 KB |
Output is correct |
70 |
Correct |
61 ms |
46188 KB |
Output is correct |
71 |
Correct |
63 ms |
46188 KB |
Output is correct |
72 |
Correct |
63 ms |
46188 KB |
Output is correct |
73 |
Correct |
64 ms |
46188 KB |
Output is correct |
74 |
Correct |
65 ms |
46188 KB |
Output is correct |
75 |
Correct |
66 ms |
46188 KB |
Output is correct |
76 |
Correct |
67 ms |
46188 KB |
Output is correct |
77 |
Correct |
67 ms |
46188 KB |
Output is correct |
78 |
Correct |
67 ms |
46188 KB |
Output is correct |
79 |
Correct |
66 ms |
46316 KB |
Output is correct |
80 |
Correct |
67 ms |
46148 KB |
Output is correct |
81 |
Correct |
66 ms |
46188 KB |
Output is correct |
82 |
Correct |
69 ms |
46188 KB |
Output is correct |
83 |
Correct |
68 ms |
46188 KB |
Output is correct |
84 |
Correct |
68 ms |
46188 KB |
Output is correct |
85 |
Correct |
69 ms |
46188 KB |
Output is correct |
86 |
Correct |
71 ms |
46188 KB |
Output is correct |
87 |
Correct |
68 ms |
46188 KB |
Output is correct |
88 |
Correct |
66 ms |
46188 KB |
Output is correct |
89 |
Correct |
69 ms |
46188 KB |
Output is correct |
90 |
Correct |
67 ms |
46116 KB |
Output is correct |