#include<bits/stdc++.h>
using namespace std;
const int N = 3001;
int matched[N * N], vis[N * N];
int iter;
bool match(int x, vector<vector<int>>& g) {
vis[x] = iter;
for(int i: g[x]) {
if(matched[i] == -1) {
matched[i] = x;
return true;
}
}
for(int i: g[x]) {
if(vis[i] != iter && match(matched[i], g)) {
matched[i] = x;
return true;
}
}
return false;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, m; cin>>n>>m;
vector<string> tab(n);
for(int i=0; i<n; ++i) {
cin>>tab[i];
}
vector<vector<bool>> horiz(n, vector<bool>(m)), vert(n, vector<bool>(m));
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;
}
}
}
vector<vector<int>> rep(n, vector<int>(m));
int nr = 0;
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;
rep[i][j] = nr;
nr++;
}
}
}
vector<vector<int>> g;
for(int i=0; i<n; ++i) {
for(int j=0; j<m; ++j) {
if(vert[i][j]) {
g.push_back({});
if(horiz[i][j]) {
g.back().push_back(rep[i][j]);
}
if(i+1<n && j+1<n && horiz[i+1][j+1]) {
g.back().push_back(rep[i+1][j+1]);
}
if(i+2<n && j+2<n && horiz[i+2][j+2]) {
g.back().push_back(rep[i+2][j+2]);
}
}
}
}
for(int i=0; i<nr; ++i) {
matched[i] = -1;
}
int sz = g.size();
for(int i=0; i<sz; ++i) {
iter++;
match(i, g);
}
int ans = 0;
for(int i=0; i<nr; ++i) {
if(matched[i] != -1) ans++;
}
cout<<sz + nr - ans;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Incorrect |
1 ms |
384 KB |
Output isn't correct |
7 |
Halted |
0 ms |
0 KB |
- |