#include <algorithm>
#include <bitset>
#include <cstdio>
#include <iostream>
#include <vector>
using namespace std;
const int N = 3005;
vector<int> g[N * N];
vector<int> st, dr;
vector<bool> f;
vector<int> used;
vector<string> mx;
int n, m, fp;
static int cod(int l, int c) {
return 1 + l * m + c; }
static bool match(int u) {
if (f[u])
return false;
f[u] = 1;
for (auto v: g[u]) if (!dr[v]) {
st[u] = v;
dr[v] = u;
return true; }
for (auto v: g[u]) if (match(dr[v])) {
st[u] = v;
dr[v] = u;
return true; }
return false;}
int main() {
#ifdef HOME
freopen("joi_dango.in", "r", stdin);
freopen("joi_dango.out", "w", stdout);
#endif
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
int add, ant;
cin >> n >> m;
mx.resize(n);
for (auto &line: mx)
cin >> line;
ant = 0;
for (int i = 0; i < n; ++i)
for (int j = 0; j < m; ++j) if (mx[i][j] == 'R') {
bool hor = j + 2 < m ? (mx[i][j + 1] == 'G' && mx[i][j + 2] == 'W') : 0;
bool ver = i + 2 < n ? (mx[i + 1][j] == 'G' && mx[i + 2][j] == 'W') : 0;
ant+= int(hor) + int(ver);
if (hor || ver)
used.push_back(cod(i, j));
if (hor && ver) {
g[used.size()].push_back(used.size()); } }
for (int i = 2; i < n; ++i)
for (int j = 2; j < m; ++j) if (mx[i][j] == 'W') {
bool hor = mx[i][j - 2] == 'R' && mx[i][j - 1] == 'G';
bool ver = mx[i - 2][j] == 'R' && mx[i - 1][j] == 'G';
if (hor && ver) {
int h = lower_bound(begin(used), end(used), cod(i - 2, j)) - begin(used) + 1;
int v = lower_bound(begin(used), end(used), cod(i, j - 2)) - begin(used) + 1;
g[v].push_back(h); } }
for (int i = 1; i < n - 1; ++i)
for (int j = 1; j < m - 1; ++j) if (mx[i][j] == 'G') {
if (mx[i - 1][j] == 'R' && mx[i + 1][j] == 'W')
if (mx[i][j - 1] == 'R' && mx[i][j + 1] == 'W') {
int h = lower_bound(begin(used), end(used), cod(i - 1, j)) - begin(used) + 1;
int v = lower_bound(begin(used), end(used), cod(i, j - 1)) - begin(used) + 1;
g[v].push_back(h); } }
mx.clear();
mx.shrink_to_fit();
st.resize(used.size() + 5);
dr.resize(used.size() + 5);
st.shrink_to_fit();
dr.shrink_to_fit();
f.resize(used.size() + 5);
f.shrink_to_fit();
for (int i = 1; i <= used.size(); ++i)
g[i].shrink_to_fit();
do {
fill(begin(f), end(f), false);
add = 0;
for (int i = 1; i <= used.size(); ++i)
if (!st[i] && !f[i])
add+= int(match(i));
ant-= add; }
while (add);
cout << ant << endl;
return 0; }
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:91:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i <= used.size(); ++i)
~~^~~~~~~~~~~~~~
dango_maker.cpp:97:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 1; i <= used.size(); ++i)
~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
212524 KB |
Output is correct |
2 |
Correct |
195 ms |
212452 KB |
Output is correct |
3 |
Correct |
192 ms |
212368 KB |
Output is correct |
4 |
Correct |
196 ms |
212540 KB |
Output is correct |
5 |
Correct |
193 ms |
212372 KB |
Output is correct |
6 |
Correct |
197 ms |
212444 KB |
Output is correct |
7 |
Correct |
203 ms |
212476 KB |
Output is correct |
8 |
Correct |
189 ms |
212344 KB |
Output is correct |
9 |
Correct |
227 ms |
212472 KB |
Output is correct |
10 |
Correct |
222 ms |
212344 KB |
Output is correct |
11 |
Correct |
192 ms |
212472 KB |
Output is correct |
12 |
Correct |
210 ms |
212324 KB |
Output is correct |
13 |
Correct |
207 ms |
212348 KB |
Output is correct |
14 |
Correct |
202 ms |
212384 KB |
Output is correct |
15 |
Correct |
226 ms |
212344 KB |
Output is correct |
16 |
Correct |
193 ms |
212348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
212524 KB |
Output is correct |
2 |
Correct |
195 ms |
212452 KB |
Output is correct |
3 |
Correct |
192 ms |
212368 KB |
Output is correct |
4 |
Correct |
196 ms |
212540 KB |
Output is correct |
5 |
Correct |
193 ms |
212372 KB |
Output is correct |
6 |
Correct |
197 ms |
212444 KB |
Output is correct |
7 |
Correct |
203 ms |
212476 KB |
Output is correct |
8 |
Correct |
189 ms |
212344 KB |
Output is correct |
9 |
Correct |
227 ms |
212472 KB |
Output is correct |
10 |
Correct |
222 ms |
212344 KB |
Output is correct |
11 |
Correct |
192 ms |
212472 KB |
Output is correct |
12 |
Correct |
210 ms |
212324 KB |
Output is correct |
13 |
Correct |
207 ms |
212348 KB |
Output is correct |
14 |
Correct |
202 ms |
212384 KB |
Output is correct |
15 |
Correct |
226 ms |
212344 KB |
Output is correct |
16 |
Correct |
193 ms |
212348 KB |
Output is correct |
17 |
Correct |
205 ms |
212416 KB |
Output is correct |
18 |
Correct |
209 ms |
212472 KB |
Output is correct |
19 |
Correct |
202 ms |
212328 KB |
Output is correct |
20 |
Correct |
231 ms |
212344 KB |
Output is correct |
21 |
Correct |
230 ms |
212344 KB |
Output is correct |
22 |
Correct |
227 ms |
212412 KB |
Output is correct |
23 |
Correct |
217 ms |
212476 KB |
Output is correct |
24 |
Correct |
215 ms |
212468 KB |
Output is correct |
25 |
Correct |
199 ms |
212396 KB |
Output is correct |
26 |
Correct |
207 ms |
212480 KB |
Output is correct |
27 |
Correct |
235 ms |
212436 KB |
Output is correct |
28 |
Correct |
209 ms |
212364 KB |
Output is correct |
29 |
Correct |
203 ms |
212344 KB |
Output is correct |
30 |
Correct |
228 ms |
212344 KB |
Output is correct |
31 |
Correct |
226 ms |
212316 KB |
Output is correct |
32 |
Correct |
211 ms |
212344 KB |
Output is correct |
33 |
Correct |
190 ms |
212344 KB |
Output is correct |
34 |
Correct |
189 ms |
212348 KB |
Output is correct |
35 |
Correct |
193 ms |
212344 KB |
Output is correct |
36 |
Correct |
194 ms |
212344 KB |
Output is correct |
37 |
Correct |
191 ms |
212472 KB |
Output is correct |
38 |
Correct |
189 ms |
212412 KB |
Output is correct |
39 |
Correct |
209 ms |
212432 KB |
Output is correct |
40 |
Correct |
197 ms |
212344 KB |
Output is correct |
41 |
Correct |
194 ms |
212344 KB |
Output is correct |
42 |
Correct |
207 ms |
212344 KB |
Output is correct |
43 |
Correct |
200 ms |
212344 KB |
Output is correct |
44 |
Correct |
197 ms |
212384 KB |
Output is correct |
45 |
Correct |
195 ms |
212344 KB |
Output is correct |
46 |
Correct |
198 ms |
212472 KB |
Output is correct |
47 |
Correct |
202 ms |
212344 KB |
Output is correct |
48 |
Correct |
211 ms |
212388 KB |
Output is correct |
49 |
Correct |
213 ms |
212344 KB |
Output is correct |
50 |
Correct |
192 ms |
212472 KB |
Output is correct |
51 |
Correct |
192 ms |
212344 KB |
Output is correct |
52 |
Correct |
195 ms |
212316 KB |
Output is correct |
53 |
Correct |
199 ms |
212472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
205 ms |
212524 KB |
Output is correct |
2 |
Correct |
195 ms |
212452 KB |
Output is correct |
3 |
Correct |
192 ms |
212368 KB |
Output is correct |
4 |
Correct |
196 ms |
212540 KB |
Output is correct |
5 |
Correct |
193 ms |
212372 KB |
Output is correct |
6 |
Correct |
197 ms |
212444 KB |
Output is correct |
7 |
Correct |
203 ms |
212476 KB |
Output is correct |
8 |
Correct |
189 ms |
212344 KB |
Output is correct |
9 |
Correct |
227 ms |
212472 KB |
Output is correct |
10 |
Correct |
222 ms |
212344 KB |
Output is correct |
11 |
Correct |
192 ms |
212472 KB |
Output is correct |
12 |
Correct |
210 ms |
212324 KB |
Output is correct |
13 |
Correct |
207 ms |
212348 KB |
Output is correct |
14 |
Correct |
202 ms |
212384 KB |
Output is correct |
15 |
Correct |
226 ms |
212344 KB |
Output is correct |
16 |
Correct |
193 ms |
212348 KB |
Output is correct |
17 |
Correct |
205 ms |
212416 KB |
Output is correct |
18 |
Correct |
209 ms |
212472 KB |
Output is correct |
19 |
Correct |
202 ms |
212328 KB |
Output is correct |
20 |
Correct |
231 ms |
212344 KB |
Output is correct |
21 |
Correct |
230 ms |
212344 KB |
Output is correct |
22 |
Correct |
227 ms |
212412 KB |
Output is correct |
23 |
Correct |
217 ms |
212476 KB |
Output is correct |
24 |
Correct |
215 ms |
212468 KB |
Output is correct |
25 |
Correct |
199 ms |
212396 KB |
Output is correct |
26 |
Correct |
207 ms |
212480 KB |
Output is correct |
27 |
Correct |
235 ms |
212436 KB |
Output is correct |
28 |
Correct |
209 ms |
212364 KB |
Output is correct |
29 |
Correct |
203 ms |
212344 KB |
Output is correct |
30 |
Correct |
228 ms |
212344 KB |
Output is correct |
31 |
Correct |
226 ms |
212316 KB |
Output is correct |
32 |
Correct |
211 ms |
212344 KB |
Output is correct |
33 |
Correct |
190 ms |
212344 KB |
Output is correct |
34 |
Correct |
189 ms |
212348 KB |
Output is correct |
35 |
Correct |
193 ms |
212344 KB |
Output is correct |
36 |
Correct |
194 ms |
212344 KB |
Output is correct |
37 |
Correct |
191 ms |
212472 KB |
Output is correct |
38 |
Correct |
189 ms |
212412 KB |
Output is correct |
39 |
Correct |
209 ms |
212432 KB |
Output is correct |
40 |
Correct |
197 ms |
212344 KB |
Output is correct |
41 |
Correct |
194 ms |
212344 KB |
Output is correct |
42 |
Correct |
207 ms |
212344 KB |
Output is correct |
43 |
Correct |
200 ms |
212344 KB |
Output is correct |
44 |
Correct |
197 ms |
212384 KB |
Output is correct |
45 |
Correct |
195 ms |
212344 KB |
Output is correct |
46 |
Correct |
198 ms |
212472 KB |
Output is correct |
47 |
Correct |
202 ms |
212344 KB |
Output is correct |
48 |
Correct |
211 ms |
212388 KB |
Output is correct |
49 |
Correct |
213 ms |
212344 KB |
Output is correct |
50 |
Correct |
192 ms |
212472 KB |
Output is correct |
51 |
Correct |
192 ms |
212344 KB |
Output is correct |
52 |
Correct |
195 ms |
212316 KB |
Output is correct |
53 |
Correct |
199 ms |
212472 KB |
Output is correct |
54 |
Correct |
210 ms |
212360 KB |
Output is correct |
55 |
Correct |
202 ms |
212472 KB |
Output is correct |
56 |
Correct |
201 ms |
212476 KB |
Output is correct |
57 |
Correct |
190 ms |
212600 KB |
Output is correct |
58 |
Correct |
249 ms |
214828 KB |
Output is correct |
59 |
Correct |
495 ms |
227856 KB |
Output is correct |
60 |
Correct |
520 ms |
228180 KB |
Output is correct |
61 |
Correct |
526 ms |
227860 KB |
Output is correct |
62 |
Correct |
199 ms |
212472 KB |
Output is correct |
63 |
Correct |
492 ms |
227364 KB |
Output is correct |
64 |
Runtime error |
298 ms |
263168 KB |
Execution killed with signal 9 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |