#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
vector<vector<int>> g;
vector<int> used, mt;
int timer = 1;
bool kuhn(int v) {
if (used[v] == timer)
return false;
used[v] = timer;
for (auto to : g[v]) {
if (mt[to] == -1) {
mt[to] = v;
return true;
}
}
for (auto to : g[v]) {
if (kuhn(mt[to])) {
mt[to] = v;
return true;
}
}
return false;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
int n, m;
cin >> n >> m;
vector<vector<int>> table(n, vector<int>(m));
for (auto& r : table) {
string s;
cin >> s;
for (int j = 0; j < m; ++j) {
if (s[j] == 'R')
r[j] = 0;
else if (s[j] == 'G')
r[j] = 1;
else
r[j] = 2;
}
}
int allcnt = 0;
vector<vector<int>> has_vert(n, vector<int>(m, -1));
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (table[i][j])
continue;
if (i + 2 < n) {
if (table[i + 1][j] == 1 && table[i + 2][j] == 2) {
has_vert[i][j] = allcnt;
mt.emplace_back(-1);
allcnt += 1;
}
}
}
}
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
if (table[i][j])
continue;
if (j + 2 < m) {
if (table[i][j + 1] == 1 && table[i][j + 2] == 2) {
allcnt += 1;
g.emplace_back();
used.emplace_back();
if (has_vert[i][j] != -1)
g[g.size() - 1].push_back(has_vert[i][j]);
if (i - 1 >= 0 && j + 1 < m && has_vert[i - 1][j + 1] != -1)
g[g.size() - 1].push_back(has_vert[i - 1][j + 1]);
if (i - 2 >= 0 && j + 2 < m && has_vert[i - 2][j + 2] != -1)
g[g.size() - 1].push_back(has_vert[i - 2][j + 2]);
}
}
}
}
for (int i = 0; i < g.size(); ++i)
if (kuhn(i))
timer += 1;
int bipmt = 0;
for (int i = 0; i < mt.size(); ++i)
if (mt[i] != -1)
bipmt += 1;
cout << allcnt - bipmt;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:81:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
81 | for (int i = 0; i < g.size(); ++i)
| ~~^~~~~~~~~~
dango_maker.cpp:85:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
85 | for (int i = 0; i < mt.size(); ++i)
| ~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
344 KB |
Output is correct |
13 |
Correct |
0 ms |
600 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
348 KB |
Output is correct |
17 |
Correct |
0 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
0 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
600 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
0 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
348 KB |
Output is correct |
37 |
Correct |
0 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
0 ms |
344 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
0 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
344 KB |
Output is correct |
43 |
Correct |
0 ms |
348 KB |
Output is correct |
44 |
Correct |
0 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
0 ms |
344 KB |
Output is correct |
47 |
Correct |
0 ms |
348 KB |
Output is correct |
48 |
Correct |
0 ms |
348 KB |
Output is correct |
49 |
Correct |
0 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
348 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
0 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
348 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
604 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
23 ms |
10364 KB |
Output is correct |
59 |
Correct |
194 ms |
98744 KB |
Output is correct |
60 |
Correct |
202 ms |
98412 KB |
Output is correct |
61 |
Correct |
205 ms |
97468 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Correct |
187 ms |
94476 KB |
Output is correct |
64 |
Correct |
655 ms |
262144 KB |
Output is correct |
65 |
Correct |
707 ms |
262144 KB |
Output is correct |
66 |
Correct |
955 ms |
262144 KB |
Output is correct |
67 |
Correct |
74 ms |
96692 KB |
Output is correct |
68 |
Correct |
77 ms |
97208 KB |
Output is correct |
69 |
Correct |
85 ms |
98264 KB |
Output is correct |
70 |
Correct |
54 ms |
32196 KB |
Output is correct |
71 |
Correct |
56 ms |
32828 KB |
Output is correct |
72 |
Correct |
57 ms |
33628 KB |
Output is correct |
73 |
Correct |
60 ms |
33552 KB |
Output is correct |
74 |
Correct |
57 ms |
32964 KB |
Output is correct |
75 |
Correct |
56 ms |
32184 KB |
Output is correct |
76 |
Correct |
64 ms |
33168 KB |
Output is correct |
77 |
Correct |
57 ms |
32448 KB |
Output is correct |
78 |
Correct |
59 ms |
32448 KB |
Output is correct |
79 |
Correct |
58 ms |
32836 KB |
Output is correct |
80 |
Correct |
62 ms |
33568 KB |
Output is correct |
81 |
Correct |
69 ms |
32124 KB |
Output is correct |
82 |
Correct |
58 ms |
33988 KB |
Output is correct |
83 |
Correct |
59 ms |
33732 KB |
Output is correct |
84 |
Correct |
58 ms |
33724 KB |
Output is correct |
85 |
Correct |
58 ms |
33216 KB |
Output is correct |
86 |
Correct |
57 ms |
32928 KB |
Output is correct |
87 |
Correct |
75 ms |
33980 KB |
Output is correct |
88 |
Correct |
74 ms |
32708 KB |
Output is correct |
89 |
Correct |
58 ms |
33988 KB |
Output is correct |
90 |
Correct |
57 ms |
32452 KB |
Output is correct |