#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
const int N = 3e3 + 50;
const int M = N * N / 3;
vector < int > v[M];
int bio[M];
bool ty[M];
int mat[M], kk[N][N][2];
char s[N][N];
int n, m, edg, cnt = 1, cookie = 1;
int dfs( int node ) {
if(bio[ node ] == cookie) return 0;
bio[ node ] = cookie;
for(int sus : v[node]){
if( bio[ sus ] != cookie && (mat[ sus ] == -1 || dfs( mat[ sus ]) )) {
mat[ sus ] = node;
return 1;
}
}
return 0;
}
int matching( ) {
int sol = 0;
memset( mat, -1, sizeof( mat ) );
for( int i = cnt - 1; i ; i--) {
if(ty[i]) continue;
cookie++;
sol += dfs(i);
}
return sol;
}
int main(){
memset(s, '.', sizeof(s));
scanf("%d%d", &n, &m);
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
char c = getchar_unlocked();
while(c != 'R' && c != 'W' && c != 'G') c = getchar_unlocked();
s[i][j] = c;
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(s[i][j] != 'G') continue;
int kol = 0;
if(s[i - 1][j] == 'R' && s[i + 1][j] == 'W'){
kk[i][j][0] = cnt;
cnt++;kol++;
}
if(s[i][j - 1] == 'R' && s[i][j + 1] == 'W'){
ty[cnt] = 1;
kk[i][j][1] = cnt;
cnt++;kol++;
}
if(kol == 2){
v[cnt - 1].push_back(cnt - 2);
v[cnt - 2].push_back(cnt - 1);
edg++;
}
}
}
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
if(i + 1 < n && j + 1 < m && s[i][j] == 'R' && s[i + 1][j] == 'G' && s[i][j + 1] == 'G' && s[i + 2][j] == 'W' && s[i][j + 2] == 'W'){
v[kk[i + 1][j][0]].push_back(kk[i][j + 1][1]);
v[kk[i][j + 1][1]].push_back(kk[i + 1][j][0]);
edg++;
}
if(i > 2 && j > 2 && s[i][j] == 'W' && s[i - 1][j] == 'G' && s[i][j - 1] == 'G' && s[i - 2][j] == 'R' && s[i][j - 2] == 'R'){
v[kk[i - 1][j][0]].push_back(kk[i][j - 1][1]);
v[kk[i][j - 1][1]].push_back(kk[i - 1][j][0]);
edg++;
}
}
}
//printf("EDG %d\n", edg);
printf("%d\n", cnt - matching() - 1);
return 0;
}
Compilation message
dango_maker.cpp: In function 'int main()':
dango_maker.cpp:45:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &m);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
94496 KB |
Output is correct |
2 |
Correct |
95 ms |
94496 KB |
Output is correct |
3 |
Correct |
100 ms |
94516 KB |
Output is correct |
4 |
Correct |
85 ms |
94568 KB |
Output is correct |
5 |
Correct |
92 ms |
94636 KB |
Output is correct |
6 |
Correct |
93 ms |
94636 KB |
Output is correct |
7 |
Correct |
116 ms |
94772 KB |
Output is correct |
8 |
Correct |
94 ms |
94772 KB |
Output is correct |
9 |
Correct |
94 ms |
94772 KB |
Output is correct |
10 |
Correct |
98 ms |
94772 KB |
Output is correct |
11 |
Correct |
101 ms |
94772 KB |
Output is correct |
12 |
Correct |
96 ms |
94772 KB |
Output is correct |
13 |
Correct |
98 ms |
94772 KB |
Output is correct |
14 |
Correct |
92 ms |
94772 KB |
Output is correct |
15 |
Correct |
92 ms |
94772 KB |
Output is correct |
16 |
Correct |
103 ms |
94772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
94496 KB |
Output is correct |
2 |
Correct |
95 ms |
94496 KB |
Output is correct |
3 |
Correct |
100 ms |
94516 KB |
Output is correct |
4 |
Correct |
85 ms |
94568 KB |
Output is correct |
5 |
Correct |
92 ms |
94636 KB |
Output is correct |
6 |
Correct |
93 ms |
94636 KB |
Output is correct |
7 |
Correct |
116 ms |
94772 KB |
Output is correct |
8 |
Correct |
94 ms |
94772 KB |
Output is correct |
9 |
Correct |
94 ms |
94772 KB |
Output is correct |
10 |
Correct |
98 ms |
94772 KB |
Output is correct |
11 |
Correct |
101 ms |
94772 KB |
Output is correct |
12 |
Correct |
96 ms |
94772 KB |
Output is correct |
13 |
Correct |
98 ms |
94772 KB |
Output is correct |
14 |
Correct |
92 ms |
94772 KB |
Output is correct |
15 |
Correct |
92 ms |
94772 KB |
Output is correct |
16 |
Correct |
103 ms |
94772 KB |
Output is correct |
17 |
Correct |
103 ms |
94772 KB |
Output is correct |
18 |
Correct |
81 ms |
94772 KB |
Output is correct |
19 |
Correct |
88 ms |
94772 KB |
Output is correct |
20 |
Correct |
79 ms |
94772 KB |
Output is correct |
21 |
Correct |
79 ms |
94772 KB |
Output is correct |
22 |
Correct |
79 ms |
94772 KB |
Output is correct |
23 |
Correct |
82 ms |
94772 KB |
Output is correct |
24 |
Correct |
117 ms |
94772 KB |
Output is correct |
25 |
Correct |
90 ms |
94772 KB |
Output is correct |
26 |
Correct |
95 ms |
94772 KB |
Output is correct |
27 |
Correct |
89 ms |
94772 KB |
Output is correct |
28 |
Correct |
93 ms |
94772 KB |
Output is correct |
29 |
Correct |
88 ms |
94772 KB |
Output is correct |
30 |
Correct |
96 ms |
94772 KB |
Output is correct |
31 |
Correct |
86 ms |
94772 KB |
Output is correct |
32 |
Correct |
90 ms |
94772 KB |
Output is correct |
33 |
Correct |
81 ms |
94772 KB |
Output is correct |
34 |
Correct |
84 ms |
94772 KB |
Output is correct |
35 |
Correct |
89 ms |
94836 KB |
Output is correct |
36 |
Correct |
129 ms |
94836 KB |
Output is correct |
37 |
Correct |
110 ms |
94836 KB |
Output is correct |
38 |
Correct |
99 ms |
94836 KB |
Output is correct |
39 |
Correct |
96 ms |
94836 KB |
Output is correct |
40 |
Correct |
84 ms |
94836 KB |
Output is correct |
41 |
Correct |
93 ms |
94836 KB |
Output is correct |
42 |
Correct |
97 ms |
94836 KB |
Output is correct |
43 |
Correct |
103 ms |
94836 KB |
Output is correct |
44 |
Correct |
87 ms |
94836 KB |
Output is correct |
45 |
Correct |
93 ms |
94836 KB |
Output is correct |
46 |
Correct |
92 ms |
94836 KB |
Output is correct |
47 |
Correct |
89 ms |
94836 KB |
Output is correct |
48 |
Correct |
136 ms |
94836 KB |
Output is correct |
49 |
Correct |
80 ms |
94836 KB |
Output is correct |
50 |
Correct |
82 ms |
94836 KB |
Output is correct |
51 |
Correct |
81 ms |
94836 KB |
Output is correct |
52 |
Correct |
93 ms |
94836 KB |
Output is correct |
53 |
Correct |
93 ms |
94836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
109 ms |
94496 KB |
Output is correct |
2 |
Correct |
95 ms |
94496 KB |
Output is correct |
3 |
Correct |
100 ms |
94516 KB |
Output is correct |
4 |
Correct |
85 ms |
94568 KB |
Output is correct |
5 |
Correct |
92 ms |
94636 KB |
Output is correct |
6 |
Correct |
93 ms |
94636 KB |
Output is correct |
7 |
Correct |
116 ms |
94772 KB |
Output is correct |
8 |
Correct |
94 ms |
94772 KB |
Output is correct |
9 |
Correct |
94 ms |
94772 KB |
Output is correct |
10 |
Correct |
98 ms |
94772 KB |
Output is correct |
11 |
Correct |
101 ms |
94772 KB |
Output is correct |
12 |
Correct |
96 ms |
94772 KB |
Output is correct |
13 |
Correct |
98 ms |
94772 KB |
Output is correct |
14 |
Correct |
92 ms |
94772 KB |
Output is correct |
15 |
Correct |
92 ms |
94772 KB |
Output is correct |
16 |
Correct |
103 ms |
94772 KB |
Output is correct |
17 |
Correct |
103 ms |
94772 KB |
Output is correct |
18 |
Correct |
81 ms |
94772 KB |
Output is correct |
19 |
Correct |
88 ms |
94772 KB |
Output is correct |
20 |
Correct |
79 ms |
94772 KB |
Output is correct |
21 |
Correct |
79 ms |
94772 KB |
Output is correct |
22 |
Correct |
79 ms |
94772 KB |
Output is correct |
23 |
Correct |
82 ms |
94772 KB |
Output is correct |
24 |
Correct |
117 ms |
94772 KB |
Output is correct |
25 |
Correct |
90 ms |
94772 KB |
Output is correct |
26 |
Correct |
95 ms |
94772 KB |
Output is correct |
27 |
Correct |
89 ms |
94772 KB |
Output is correct |
28 |
Correct |
93 ms |
94772 KB |
Output is correct |
29 |
Correct |
88 ms |
94772 KB |
Output is correct |
30 |
Correct |
96 ms |
94772 KB |
Output is correct |
31 |
Correct |
86 ms |
94772 KB |
Output is correct |
32 |
Correct |
90 ms |
94772 KB |
Output is correct |
33 |
Correct |
81 ms |
94772 KB |
Output is correct |
34 |
Correct |
84 ms |
94772 KB |
Output is correct |
35 |
Correct |
89 ms |
94836 KB |
Output is correct |
36 |
Correct |
129 ms |
94836 KB |
Output is correct |
37 |
Correct |
110 ms |
94836 KB |
Output is correct |
38 |
Correct |
99 ms |
94836 KB |
Output is correct |
39 |
Correct |
96 ms |
94836 KB |
Output is correct |
40 |
Correct |
84 ms |
94836 KB |
Output is correct |
41 |
Correct |
93 ms |
94836 KB |
Output is correct |
42 |
Correct |
97 ms |
94836 KB |
Output is correct |
43 |
Correct |
103 ms |
94836 KB |
Output is correct |
44 |
Correct |
87 ms |
94836 KB |
Output is correct |
45 |
Correct |
93 ms |
94836 KB |
Output is correct |
46 |
Correct |
92 ms |
94836 KB |
Output is correct |
47 |
Correct |
89 ms |
94836 KB |
Output is correct |
48 |
Correct |
136 ms |
94836 KB |
Output is correct |
49 |
Correct |
80 ms |
94836 KB |
Output is correct |
50 |
Correct |
82 ms |
94836 KB |
Output is correct |
51 |
Correct |
81 ms |
94836 KB |
Output is correct |
52 |
Correct |
93 ms |
94836 KB |
Output is correct |
53 |
Correct |
93 ms |
94836 KB |
Output is correct |
54 |
Correct |
99 ms |
94836 KB |
Output is correct |
55 |
Correct |
103 ms |
95188 KB |
Output is correct |
56 |
Correct |
97 ms |
95188 KB |
Output is correct |
57 |
Correct |
90 ms |
101756 KB |
Output is correct |
58 |
Correct |
134 ms |
107644 KB |
Output is correct |
59 |
Correct |
496 ms |
184784 KB |
Output is correct |
60 |
Correct |
509 ms |
193564 KB |
Output is correct |
61 |
Correct |
563 ms |
202488 KB |
Output is correct |
62 |
Correct |
84 ms |
202488 KB |
Output is correct |
63 |
Correct |
595 ms |
210680 KB |
Output is correct |
64 |
Execution timed out |
2078 ms |
263168 KB |
Time limit exceeded |
65 |
Halted |
0 ms |
0 KB |
- |