#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ll long long
#define f first
#define s second
#define FOR(i,a,b) for (int i = a; i<b; i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for (int i = n-1; i>=0; i--)
#define SZ(x) (int)(x.size())
#define ALL(x) x.begin(),x.end()
#define MX(a,b) a = max(a,(__typeof__(a))(b))
#define MN(a,b) a = min(a,(__typeof__(a))(b))
#define pb push_back
#ifdef BALBIT
#define IOS()
#define bug(x) cerr<<__LINE__<<' '<<#x<<": "<<x<<endl
#else
#define IOS() ios::sync_with_stdio(0),cin.tie(0)
#define endl '\n'
#define bug(x)
#endif
const ll mod = 1e9+7;
const int maxn = 3e3+5;
//const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iinf = 0x3f3f3f3f;
#define MAX 300001
#define NIL 0
#define INF (1<<28)
vector< int > G[MAX];
int N, M, match[MAX], dist[MAX];
// n: number of nodes on left side, nodes are numbered 1 to n
// m: number of nodes on right side, nodes are numbered n+1 to n+m
// G = NIL[0] ∪ G1[G[1---n]] ∪ G2[G[n+1---n+m]]
bool bfs() {
int i, u, v, len;
queue< int > Q;
for(i=1; i<=N; i++) {
if(match[i]==NIL) {
dist[i] = 0;
Q.push(i);
}
else dist[i] = INF;
}
dist[NIL] = INF;
while(!Q.empty()) {
u = Q.front(); Q.pop();
if(u!=NIL) {
len = G[u].size();
for(i=0; i<len; i++) {
v = G[u][i];
if(dist[match[v]]==INF) {
dist[match[v]] = dist[u] + 1;
Q.push(match[v]);
}
}
}
}
return (dist[NIL]!=INF);
}
bool dfs(int u) {
int i, v, len;
if(u!=NIL) {
len = G[u].size();
for(i=0; i<len; i++) {
v = G[u][i];
if(dist[match[v]]==dist[u]+1) {
if(dfs(match[v])) {
match[v] = u;
match[u] = v;
return true;
}
}
}
dist[u] = INF;
return false;
}
return true;
}
int hopcroft_karp() {
int matching = 0, i;
// match[] is assumed NIL for all vertex in G
while(bfs())
for(i=1; i<=N; i++)
if(match[i]==NIL && dfs(i))
matching++;
return matching;
}
char grd[maxn][maxn];
int idup[maxn][maxn];
int idrt[maxn][maxn];
bool up[maxn][maxn];
bool rt[maxn][maxn];
void add(int a, int b, int c){
// return;
G[a].pb(b);
}
signed main(){
IOS();
int n, m; cin>>n>>m;
REP(i,n) REP(j,m) cin>>grd[i][j];
int nup = 0, nrt = 0;
REP(i,n)REP(j,m){
if(grd[i][j]=='G'){
if (i && i!=n-1 && grd[i-1][j] == 'R' && grd[i+1][j]=='W' ) {
up[i][j] = 1;
}
if (j && j!=m-1 && grd[i][j-1] == 'R' && grd[i][j+1]=='W' ) {
rt[i][j] = 1;
}
}
}
// g.resize(N); ptr.resize(N); level.resize(N);
int ans = 0;
REP(i,n) REP(j,m){
if(up[i][j]){
// cout<<i<<' '<<j<<' '<<idup[i][j]<<endl;
bool B = 0;
if(rt[i][j]) B=1, idrt[i][j] = 1;
if(i && rt[i-1][j+1]) B=1, idrt[i-1][j+1] = 1;
if(j && rt[i+1][j-1]) B=1, idrt[i+1][j-1] = 1;
nup += B;
idup[i][j] = B;
if (!B) ans ++;
}
}
int nat = 0;
REP(i,n) REP(j,m){
if (idrt[i][j]){
idrt[i][j] = ++nat;
}else if (rt[i][j]) ans ++;
}
nrt = nat;
nat = 0;
REP(i,n) REP(j,m){
if(idup[i][j]){
idup[i][j] = ++nat;
// cout<<i<<' '<<j<<' '<<idup[i][j]<<endl;
if(idrt[i][j]) {
add(idup[i][j], idrt[i][j] + nup, iinf);
}
if(i && idrt[i-1][j+1]){
add(idup[i][j], idrt[i-1][j+1] + nup, iinf);
}
if(j && idrt[i+1][j-1]){
add(idup[i][j], idrt[i+1][j-1] + nup, iinf);
}
}
}
bug(ans);
N = nup;
bug(nup); bug(nrt);
cout<<ans + nup + nrt - hopcroft_karp() << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7412 KB |
Output is correct |
5 |
Correct |
9 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Correct |
8 ms |
7416 KB |
Output is correct |
8 |
Correct |
8 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
10 ms |
7364 KB |
Output is correct |
11 |
Correct |
8 ms |
7544 KB |
Output is correct |
12 |
Correct |
9 ms |
7416 KB |
Output is correct |
13 |
Correct |
7 ms |
7388 KB |
Output is correct |
14 |
Correct |
8 ms |
7416 KB |
Output is correct |
15 |
Correct |
8 ms |
7416 KB |
Output is correct |
16 |
Correct |
8 ms |
7416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7412 KB |
Output is correct |
5 |
Correct |
9 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Correct |
8 ms |
7416 KB |
Output is correct |
8 |
Correct |
8 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
10 ms |
7364 KB |
Output is correct |
11 |
Correct |
8 ms |
7544 KB |
Output is correct |
12 |
Correct |
9 ms |
7416 KB |
Output is correct |
13 |
Correct |
7 ms |
7388 KB |
Output is correct |
14 |
Correct |
8 ms |
7416 KB |
Output is correct |
15 |
Correct |
8 ms |
7416 KB |
Output is correct |
16 |
Correct |
8 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
8 ms |
7416 KB |
Output is correct |
19 |
Correct |
8 ms |
7548 KB |
Output is correct |
20 |
Correct |
8 ms |
7544 KB |
Output is correct |
21 |
Correct |
8 ms |
7460 KB |
Output is correct |
22 |
Correct |
8 ms |
7544 KB |
Output is correct |
23 |
Correct |
9 ms |
7416 KB |
Output is correct |
24 |
Correct |
8 ms |
7416 KB |
Output is correct |
25 |
Correct |
8 ms |
7416 KB |
Output is correct |
26 |
Correct |
8 ms |
7416 KB |
Output is correct |
27 |
Correct |
8 ms |
7544 KB |
Output is correct |
28 |
Correct |
8 ms |
7544 KB |
Output is correct |
29 |
Correct |
9 ms |
7544 KB |
Output is correct |
30 |
Correct |
9 ms |
7544 KB |
Output is correct |
31 |
Correct |
9 ms |
7416 KB |
Output is correct |
32 |
Correct |
9 ms |
7416 KB |
Output is correct |
33 |
Correct |
8 ms |
7544 KB |
Output is correct |
34 |
Correct |
8 ms |
7544 KB |
Output is correct |
35 |
Correct |
8 ms |
7544 KB |
Output is correct |
36 |
Correct |
8 ms |
7544 KB |
Output is correct |
37 |
Correct |
9 ms |
7544 KB |
Output is correct |
38 |
Correct |
9 ms |
7544 KB |
Output is correct |
39 |
Correct |
10 ms |
7544 KB |
Output is correct |
40 |
Correct |
9 ms |
7544 KB |
Output is correct |
41 |
Correct |
8 ms |
7544 KB |
Output is correct |
42 |
Correct |
9 ms |
7544 KB |
Output is correct |
43 |
Correct |
8 ms |
7544 KB |
Output is correct |
44 |
Correct |
8 ms |
7544 KB |
Output is correct |
45 |
Correct |
9 ms |
7544 KB |
Output is correct |
46 |
Correct |
9 ms |
7544 KB |
Output is correct |
47 |
Correct |
8 ms |
7544 KB |
Output is correct |
48 |
Correct |
9 ms |
7544 KB |
Output is correct |
49 |
Correct |
9 ms |
7544 KB |
Output is correct |
50 |
Correct |
9 ms |
7544 KB |
Output is correct |
51 |
Correct |
9 ms |
7544 KB |
Output is correct |
52 |
Correct |
9 ms |
7544 KB |
Output is correct |
53 |
Correct |
9 ms |
7544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
11 ms |
7416 KB |
Output is correct |
2 |
Correct |
8 ms |
7416 KB |
Output is correct |
3 |
Correct |
8 ms |
7416 KB |
Output is correct |
4 |
Correct |
8 ms |
7412 KB |
Output is correct |
5 |
Correct |
9 ms |
7416 KB |
Output is correct |
6 |
Correct |
8 ms |
7416 KB |
Output is correct |
7 |
Correct |
8 ms |
7416 KB |
Output is correct |
8 |
Correct |
8 ms |
7416 KB |
Output is correct |
9 |
Correct |
8 ms |
7416 KB |
Output is correct |
10 |
Correct |
10 ms |
7364 KB |
Output is correct |
11 |
Correct |
8 ms |
7544 KB |
Output is correct |
12 |
Correct |
9 ms |
7416 KB |
Output is correct |
13 |
Correct |
7 ms |
7388 KB |
Output is correct |
14 |
Correct |
8 ms |
7416 KB |
Output is correct |
15 |
Correct |
8 ms |
7416 KB |
Output is correct |
16 |
Correct |
8 ms |
7416 KB |
Output is correct |
17 |
Correct |
9 ms |
7416 KB |
Output is correct |
18 |
Correct |
8 ms |
7416 KB |
Output is correct |
19 |
Correct |
8 ms |
7548 KB |
Output is correct |
20 |
Correct |
8 ms |
7544 KB |
Output is correct |
21 |
Correct |
8 ms |
7460 KB |
Output is correct |
22 |
Correct |
8 ms |
7544 KB |
Output is correct |
23 |
Correct |
9 ms |
7416 KB |
Output is correct |
24 |
Correct |
8 ms |
7416 KB |
Output is correct |
25 |
Correct |
8 ms |
7416 KB |
Output is correct |
26 |
Correct |
8 ms |
7416 KB |
Output is correct |
27 |
Correct |
8 ms |
7544 KB |
Output is correct |
28 |
Correct |
8 ms |
7544 KB |
Output is correct |
29 |
Correct |
9 ms |
7544 KB |
Output is correct |
30 |
Correct |
9 ms |
7544 KB |
Output is correct |
31 |
Correct |
9 ms |
7416 KB |
Output is correct |
32 |
Correct |
9 ms |
7416 KB |
Output is correct |
33 |
Correct |
8 ms |
7544 KB |
Output is correct |
34 |
Correct |
8 ms |
7544 KB |
Output is correct |
35 |
Correct |
8 ms |
7544 KB |
Output is correct |
36 |
Correct |
8 ms |
7544 KB |
Output is correct |
37 |
Correct |
9 ms |
7544 KB |
Output is correct |
38 |
Correct |
9 ms |
7544 KB |
Output is correct |
39 |
Correct |
10 ms |
7544 KB |
Output is correct |
40 |
Correct |
9 ms |
7544 KB |
Output is correct |
41 |
Correct |
8 ms |
7544 KB |
Output is correct |
42 |
Correct |
9 ms |
7544 KB |
Output is correct |
43 |
Correct |
8 ms |
7544 KB |
Output is correct |
44 |
Correct |
8 ms |
7544 KB |
Output is correct |
45 |
Correct |
9 ms |
7544 KB |
Output is correct |
46 |
Correct |
9 ms |
7544 KB |
Output is correct |
47 |
Correct |
8 ms |
7544 KB |
Output is correct |
48 |
Correct |
9 ms |
7544 KB |
Output is correct |
49 |
Correct |
9 ms |
7544 KB |
Output is correct |
50 |
Correct |
9 ms |
7544 KB |
Output is correct |
51 |
Correct |
9 ms |
7544 KB |
Output is correct |
52 |
Correct |
9 ms |
7544 KB |
Output is correct |
53 |
Correct |
9 ms |
7544 KB |
Output is correct |
54 |
Correct |
9 ms |
7416 KB |
Output is correct |
55 |
Correct |
29 ms |
17272 KB |
Output is correct |
56 |
Correct |
9 ms |
7544 KB |
Output is correct |
57 |
Correct |
33 ms |
29028 KB |
Output is correct |
58 |
Correct |
59 ms |
31992 KB |
Output is correct |
59 |
Correct |
356 ms |
108880 KB |
Output is correct |
60 |
Correct |
379 ms |
109008 KB |
Output is correct |
61 |
Correct |
357 ms |
109012 KB |
Output is correct |
62 |
Correct |
9 ms |
7416 KB |
Output is correct |
63 |
Correct |
352 ms |
108824 KB |
Output is correct |
64 |
Runtime error |
470 ms |
239224 KB |
Execution killed with signal 11 (could be triggered by violating memory limits) |
65 |
Halted |
0 ms |
0 KB |
- |