#include<bits/stdc++.h>
using namespace std;
const int N = 3001;
int n, m, nr;
int matched[N * N], vis[N * N];
int iter;
bool horiz[N][N], vert[N][N];
string tab[N];
vector<int> vx = {0, -1, -2}, vy = {0, 1, 2};
bool ok(int x, int y) {
if(x>=0 && y<m && horiz[x][y]) return true;
return false;
}
int convert(int x, int y) {
return x*m + y;
}
bool match(int x) {
vis[x] = iter;
for(int i=0; i<3; ++i) {
int X = x/m + vx[i], Y = x%m + vy[i];
int rep = convert(X, Y);
if(ok(X, Y) && matched[rep]==-1) {
matched[rep] = x;
return true;
}
}
for(int i=0; i<3; ++i) {
int X = x/m + vx[i], Y = x%m + vy[i];
int rep = convert(X, Y);
if(ok(X, Y) && vis[matched[rep]] != iter && match(matched[rep])) {
matched[rep] = x;
return true;
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin>>n>>m;
for(int i=0; i<n; ++i) {
cin>>tab[i];
}
int sz = 0;
vector<int> cand;
for(int i=0; i<n; ++i) { // left - right
for(int j=0; j+2<m; ++j) {
if(tab[i][j] == 'R' && tab[i][j+1] == 'G' && tab[i][j+2] == 'W') {
vert[i][j] = 1;
sz++;
cand.push_back(convert(i, j));
}
}
}
for(int i=0; i+2<n; ++i) { // top - bottom
for(int j=0; j<m; ++j) {
if(tab[i][j] == 'R' && tab[i+1][j] == 'G' && tab[i+2][j] == 'W') {
horiz[i][j] = 1;
nr++;
}
}
}
for(int i=0; i<n*m; ++i) {
matched[i] = -1;
}
int ans = 0;
for(int i=0; i<sz; ++i) {
iter++;
match(cand[i]);
}
for(int i=0; i<n*m; ++i) {
if(matched[i] != -1) {
ans++;
}
}
cout<<nr + sz - ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Correct |
0 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Correct |
0 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
0 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
0 ms |
512 KB |
Output is correct |
33 |
Correct |
0 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
0 ms |
512 KB |
Output is correct |
36 |
Correct |
1 ms |
512 KB |
Output is correct |
37 |
Correct |
1 ms |
512 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
1 ms |
512 KB |
Output is correct |
41 |
Correct |
1 ms |
512 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
1 ms |
512 KB |
Output is correct |
45 |
Correct |
1 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
1 ms |
512 KB |
Output is correct |
50 |
Correct |
1 ms |
512 KB |
Output is correct |
51 |
Correct |
1 ms |
512 KB |
Output is correct |
52 |
Correct |
1 ms |
512 KB |
Output is correct |
53 |
Correct |
0 ms |
512 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
1 ms |
512 KB |
Output is correct |
8 |
Correct |
1 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
0 ms |
384 KB |
Output is correct |
11 |
Correct |
0 ms |
512 KB |
Output is correct |
12 |
Correct |
0 ms |
512 KB |
Output is correct |
13 |
Correct |
1 ms |
512 KB |
Output is correct |
14 |
Correct |
0 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
384 KB |
Output is correct |
17 |
Correct |
1 ms |
512 KB |
Output is correct |
18 |
Correct |
0 ms |
512 KB |
Output is correct |
19 |
Correct |
1 ms |
512 KB |
Output is correct |
20 |
Correct |
1 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
1 ms |
512 KB |
Output is correct |
23 |
Correct |
1 ms |
512 KB |
Output is correct |
24 |
Correct |
1 ms |
512 KB |
Output is correct |
25 |
Correct |
1 ms |
384 KB |
Output is correct |
26 |
Correct |
1 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
512 KB |
Output is correct |
28 |
Correct |
1 ms |
512 KB |
Output is correct |
29 |
Correct |
1 ms |
512 KB |
Output is correct |
30 |
Correct |
1 ms |
512 KB |
Output is correct |
31 |
Correct |
1 ms |
512 KB |
Output is correct |
32 |
Correct |
0 ms |
512 KB |
Output is correct |
33 |
Correct |
0 ms |
512 KB |
Output is correct |
34 |
Correct |
1 ms |
512 KB |
Output is correct |
35 |
Correct |
0 ms |
512 KB |
Output is correct |
36 |
Correct |
1 ms |
512 KB |
Output is correct |
37 |
Correct |
1 ms |
512 KB |
Output is correct |
38 |
Correct |
1 ms |
512 KB |
Output is correct |
39 |
Correct |
1 ms |
512 KB |
Output is correct |
40 |
Correct |
1 ms |
512 KB |
Output is correct |
41 |
Correct |
1 ms |
512 KB |
Output is correct |
42 |
Correct |
1 ms |
512 KB |
Output is correct |
43 |
Correct |
1 ms |
512 KB |
Output is correct |
44 |
Correct |
1 ms |
512 KB |
Output is correct |
45 |
Correct |
1 ms |
512 KB |
Output is correct |
46 |
Correct |
1 ms |
512 KB |
Output is correct |
47 |
Correct |
1 ms |
512 KB |
Output is correct |
48 |
Correct |
1 ms |
512 KB |
Output is correct |
49 |
Correct |
1 ms |
512 KB |
Output is correct |
50 |
Correct |
1 ms |
512 KB |
Output is correct |
51 |
Correct |
1 ms |
512 KB |
Output is correct |
52 |
Correct |
1 ms |
512 KB |
Output is correct |
53 |
Correct |
0 ms |
512 KB |
Output is correct |
54 |
Correct |
1 ms |
512 KB |
Output is correct |
55 |
Correct |
1 ms |
896 KB |
Output is correct |
56 |
Correct |
1 ms |
640 KB |
Output is correct |
57 |
Correct |
6 ms |
8832 KB |
Output is correct |
58 |
Correct |
26 ms |
15488 KB |
Output is correct |
59 |
Correct |
218 ms |
108528 KB |
Output is correct |
60 |
Correct |
209 ms |
106988 KB |
Output is correct |
61 |
Correct |
211 ms |
106968 KB |
Output is correct |
62 |
Correct |
1 ms |
512 KB |
Output is correct |
63 |
Correct |
203 ms |
104292 KB |
Output is correct |
64 |
Correct |
368 ms |
117572 KB |
Output is correct |
65 |
Correct |
394 ms |
117572 KB |
Output is correct |
66 |
Correct |
502 ms |
117580 KB |
Output is correct |
67 |
Correct |
78 ms |
59640 KB |
Output is correct |
68 |
Correct |
77 ms |
60024 KB |
Output is correct |
69 |
Correct |
88 ms |
76152 KB |
Output is correct |
70 |
Correct |
36 ms |
17644 KB |
Output is correct |
71 |
Correct |
33 ms |
17652 KB |
Output is correct |
72 |
Correct |
34 ms |
17652 KB |
Output is correct |
73 |
Correct |
34 ms |
17696 KB |
Output is correct |
74 |
Correct |
34 ms |
17652 KB |
Output is correct |
75 |
Correct |
39 ms |
17680 KB |
Output is correct |
76 |
Correct |
34 ms |
17644 KB |
Output is correct |
77 |
Correct |
35 ms |
17652 KB |
Output is correct |
78 |
Correct |
33 ms |
17652 KB |
Output is correct |
79 |
Correct |
33 ms |
17692 KB |
Output is correct |
80 |
Correct |
34 ms |
17652 KB |
Output is correct |
81 |
Correct |
33 ms |
17780 KB |
Output is correct |
82 |
Correct |
34 ms |
17644 KB |
Output is correct |
83 |
Correct |
35 ms |
17768 KB |
Output is correct |
84 |
Correct |
34 ms |
17644 KB |
Output is correct |
85 |
Correct |
35 ms |
17644 KB |
Output is correct |
86 |
Correct |
35 ms |
17652 KB |
Output is correct |
87 |
Correct |
37 ms |
17820 KB |
Output is correct |
88 |
Correct |
34 ms |
17652 KB |
Output is correct |
89 |
Correct |
33 ms |
17652 KB |
Output is correct |
90 |
Correct |
33 ms |
17644 KB |
Output is correct |