이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
const int MAXN = 5000;
int n, m;
string mp[MAXN+1], ss;
int p[MAXN+1][MAXN+1];
int a, b;
int ans;
vector <vector<int>> path;
bool sy[MAXN+1];
bool vis[MAXN+1];
bool dfs(int now) {
for (int i : path[now]) {
if (!sy[i] || (!vis[sy[i]] && dfs(sy[i]))) {
vis[now] = 1;
sy[i] = now;
return 1;
}
}
return 0;
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> m;
for (int i = 1; i <= n; i++) {
cin >> ss;
mp[i] = ' ' + ss;
}
path.pb(vector<int>());
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (i >= 3 && mp[i][j] == 'W' && mp[i-1][j] == 'G' && mp[i-2][j] == 'R') {
a++;
p[i][j] = p[i-1][j] = p[i-2][j] = a;
}
}
}
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
if (j >= 3 && mp[i][j] == 'W' && mp[i][j-1] == 'G' && mp[i][j-2] == 'R') {
b++, path.pb(vector<int>());
if (p[i][j ]) path[b].pb(p[i][j ]);
if (p[i][j-1]) path[b].pb(p[i][j-1]);
if (p[i][j-2]) path[b].pb(p[i][j-2]);
}
}
}
ans = a+b;
for (int i = 1; i <= b; i++) {
for (int j = 1; j <= b; j++) vis[j] = 0;
for (int j : path[i]) {
if (!sy[j] || (!vis[sy[j]] && dfs(sy[j]))) {
vis[i] = 1;
sy[j] = i;
ans--;
break;
}
}
}
cout << ans << "\n";
return 0;
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |