#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[rep] != iter && match(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 |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 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 |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 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 |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
512 KB |
Output is correct |
18 |
Correct |
0 ms |
512 KB |
Output is correct |
19 |
Correct |
0 ms |
512 KB |
Output is correct |
20 |
Correct |
0 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
0 ms |
512 KB |
Output is correct |
23 |
Correct |
0 ms |
512 KB |
Output is correct |
24 |
Correct |
0 ms |
512 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
512 KB |
Output is correct |
7 |
Correct |
0 ms |
512 KB |
Output is correct |
8 |
Correct |
0 ms |
512 KB |
Output is correct |
9 |
Correct |
1 ms |
512 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 |
0 ms |
512 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
0 ms |
384 KB |
Output is correct |
16 |
Correct |
0 ms |
384 KB |
Output is correct |
17 |
Correct |
0 ms |
512 KB |
Output is correct |
18 |
Correct |
0 ms |
512 KB |
Output is correct |
19 |
Correct |
0 ms |
512 KB |
Output is correct |
20 |
Correct |
0 ms |
512 KB |
Output is correct |
21 |
Correct |
1 ms |
512 KB |
Output is correct |
22 |
Correct |
0 ms |
512 KB |
Output is correct |
23 |
Correct |
0 ms |
512 KB |
Output is correct |
24 |
Correct |
0 ms |
512 KB |
Output is correct |
25 |
Correct |
0 ms |
384 KB |
Output is correct |
26 |
Correct |
0 ms |
384 KB |
Output is correct |
27 |
Incorrect |
1 ms |
512 KB |
Output isn't correct |
28 |
Halted |
0 ms |
0 KB |
- |