#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;
int mx[maxn*maxn/3],my[maxn*maxn/3];
bool vy[maxn*maxn/3];
vector<int> edge[maxn*maxn/3];
vector<int>id;
clock_t stT;
int N, M;
int greedy_matching()
{
int c = 0;
for (int x=0; x<N; ++x) {
int at = id[x];
if (mx[at] == -1) {
for (auto y : edge[at]) {
if (my[y] == -1) {
mx[at] = y; my[y] = at;
c++;
break;
}
}
}
}
return c;
}
bool DFS(int x)
{
for (auto y : edge[x]) {
if (!vy[y]) {
vy[y] = true;
if (my[y] == -1 || DFS(my[y]))
{
mx[x] = y; my[y] = x;
return true;
}
}
}
return false;
}
int bipartite_matching()
{
memset(mx, -1, sizeof(mx));
memset(my, -1, sizeof(my));
REP(i,N) id.pb(i); random_shuffle (ALL(id));
int c = greedy_matching();
for (int x=0; x<N; ++x){
if (mx[id[x]] == -1)
{
fill(vy, vy+M, 0);
if (DFS(id[x])) c++;
if(clock()- stT >= CLOCKS_PER_SEC * 1.9) return c;
}
}
return c;
}
char grd[maxn][maxn];
int idup[maxn][maxn];
int idrt[maxn][maxn];
signed main(){
IOS();
srand(time(0));
stT = clock();
int n, m; cin>>n>>m;
// assert(n!=3000 || m!=3000);
REP(i,n) REP(j,m) cin>>grd[i][j];
int nup = 0, nrt = 0;
memset(idup, -1, sizeof(idup));
memset(idrt, -1, sizeof(idrt));
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' ) {
idup[i][j] = nup++;
}
if (j && j!=m-1 && grd[i][j-1] == 'R' && grd[i][j+1]=='W' ) {
idrt[i][j] = nrt ++;
}
}
}
N = nup; M = nrt;
// Dinic dd (N,S,T);
REP(i,n) REP(j,m){
if(idup[i][j]!=-1){
// cout<<i<<' '<<j<<' '<<idup[i][j]<<endl;
if(idrt[i][j] != -1) {
edge[idup[i][j]].pb(idrt[i][j]);
}
if(i && idrt[i-1][j+1]!=-1){
edge[idup[i][j]].pb(idrt[i-1][j+1]);
}
if(j && idrt[i+1][j-1]!=-1){
edge[idup[i][j]].pb(idrt[i+1][j-1]);
}
}
}
cout<<nup + nrt - bipartite_matching() << endl;
}
Compilation message
dango_maker.cpp: In function 'int bipartite_matching()':
dango_maker.cpp:7:20: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
#define FOR(i,a,b) for (int i = a; i<b; i++)
^
dango_maker.cpp:8:18: note: in expansion of macro 'FOR'
#define REP(i,n) FOR(i,0,n)
^~~
dango_maker.cpp:73:3: note: in expansion of macro 'REP'
REP(i,N) id.pb(i); random_shuffle (ALL(id));
^~~
dango_maker.cpp:73:22: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
REP(i,N) id.pb(i); random_shuffle (ALL(id));
^~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
165368 KB |
Output is correct |
2 |
Correct |
152 ms |
165240 KB |
Output is correct |
3 |
Correct |
158 ms |
165324 KB |
Output is correct |
4 |
Correct |
155 ms |
165304 KB |
Output is correct |
5 |
Correct |
153 ms |
165240 KB |
Output is correct |
6 |
Correct |
158 ms |
165340 KB |
Output is correct |
7 |
Correct |
154 ms |
165300 KB |
Output is correct |
8 |
Correct |
150 ms |
165340 KB |
Output is correct |
9 |
Correct |
151 ms |
165240 KB |
Output is correct |
10 |
Correct |
153 ms |
165368 KB |
Output is correct |
11 |
Correct |
152 ms |
165348 KB |
Output is correct |
12 |
Correct |
158 ms |
165428 KB |
Output is correct |
13 |
Correct |
152 ms |
165216 KB |
Output is correct |
14 |
Correct |
152 ms |
165380 KB |
Output is correct |
15 |
Correct |
152 ms |
165240 KB |
Output is correct |
16 |
Correct |
152 ms |
165228 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
165368 KB |
Output is correct |
2 |
Correct |
152 ms |
165240 KB |
Output is correct |
3 |
Correct |
158 ms |
165324 KB |
Output is correct |
4 |
Correct |
155 ms |
165304 KB |
Output is correct |
5 |
Correct |
153 ms |
165240 KB |
Output is correct |
6 |
Correct |
158 ms |
165340 KB |
Output is correct |
7 |
Correct |
154 ms |
165300 KB |
Output is correct |
8 |
Correct |
150 ms |
165340 KB |
Output is correct |
9 |
Correct |
151 ms |
165240 KB |
Output is correct |
10 |
Correct |
153 ms |
165368 KB |
Output is correct |
11 |
Correct |
152 ms |
165348 KB |
Output is correct |
12 |
Correct |
158 ms |
165428 KB |
Output is correct |
13 |
Correct |
152 ms |
165216 KB |
Output is correct |
14 |
Correct |
152 ms |
165380 KB |
Output is correct |
15 |
Correct |
152 ms |
165240 KB |
Output is correct |
16 |
Correct |
152 ms |
165228 KB |
Output is correct |
17 |
Correct |
150 ms |
165368 KB |
Output is correct |
18 |
Correct |
151 ms |
165468 KB |
Output is correct |
19 |
Correct |
153 ms |
165368 KB |
Output is correct |
20 |
Correct |
224 ms |
165404 KB |
Output is correct |
21 |
Correct |
152 ms |
165368 KB |
Output is correct |
22 |
Correct |
151 ms |
165368 KB |
Output is correct |
23 |
Correct |
163 ms |
165268 KB |
Output is correct |
24 |
Correct |
159 ms |
165376 KB |
Output is correct |
25 |
Correct |
155 ms |
165416 KB |
Output is correct |
26 |
Correct |
159 ms |
165212 KB |
Output is correct |
27 |
Correct |
162 ms |
165364 KB |
Output is correct |
28 |
Correct |
156 ms |
165340 KB |
Output is correct |
29 |
Correct |
151 ms |
165368 KB |
Output is correct |
30 |
Correct |
172 ms |
165368 KB |
Output is correct |
31 |
Correct |
151 ms |
165368 KB |
Output is correct |
32 |
Correct |
152 ms |
165368 KB |
Output is correct |
33 |
Correct |
151 ms |
165340 KB |
Output is correct |
34 |
Correct |
150 ms |
165268 KB |
Output is correct |
35 |
Correct |
152 ms |
165496 KB |
Output is correct |
36 |
Correct |
154 ms |
165268 KB |
Output is correct |
37 |
Correct |
150 ms |
165368 KB |
Output is correct |
38 |
Correct |
153 ms |
165372 KB |
Output is correct |
39 |
Correct |
151 ms |
165368 KB |
Output is correct |
40 |
Correct |
154 ms |
165320 KB |
Output is correct |
41 |
Correct |
152 ms |
165240 KB |
Output is correct |
42 |
Correct |
152 ms |
165296 KB |
Output is correct |
43 |
Correct |
152 ms |
165268 KB |
Output is correct |
44 |
Correct |
151 ms |
165296 KB |
Output is correct |
45 |
Correct |
151 ms |
165372 KB |
Output is correct |
46 |
Correct |
152 ms |
165288 KB |
Output is correct |
47 |
Correct |
155 ms |
165368 KB |
Output is correct |
48 |
Correct |
151 ms |
165368 KB |
Output is correct |
49 |
Correct |
151 ms |
165348 KB |
Output is correct |
50 |
Correct |
151 ms |
165368 KB |
Output is correct |
51 |
Correct |
152 ms |
165344 KB |
Output is correct |
52 |
Correct |
151 ms |
165240 KB |
Output is correct |
53 |
Correct |
152 ms |
165340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
152 ms |
165368 KB |
Output is correct |
2 |
Correct |
152 ms |
165240 KB |
Output is correct |
3 |
Correct |
158 ms |
165324 KB |
Output is correct |
4 |
Correct |
155 ms |
165304 KB |
Output is correct |
5 |
Correct |
153 ms |
165240 KB |
Output is correct |
6 |
Correct |
158 ms |
165340 KB |
Output is correct |
7 |
Correct |
154 ms |
165300 KB |
Output is correct |
8 |
Correct |
150 ms |
165340 KB |
Output is correct |
9 |
Correct |
151 ms |
165240 KB |
Output is correct |
10 |
Correct |
153 ms |
165368 KB |
Output is correct |
11 |
Correct |
152 ms |
165348 KB |
Output is correct |
12 |
Correct |
158 ms |
165428 KB |
Output is correct |
13 |
Correct |
152 ms |
165216 KB |
Output is correct |
14 |
Correct |
152 ms |
165380 KB |
Output is correct |
15 |
Correct |
152 ms |
165240 KB |
Output is correct |
16 |
Correct |
152 ms |
165228 KB |
Output is correct |
17 |
Correct |
150 ms |
165368 KB |
Output is correct |
18 |
Correct |
151 ms |
165468 KB |
Output is correct |
19 |
Correct |
153 ms |
165368 KB |
Output is correct |
20 |
Correct |
224 ms |
165404 KB |
Output is correct |
21 |
Correct |
152 ms |
165368 KB |
Output is correct |
22 |
Correct |
151 ms |
165368 KB |
Output is correct |
23 |
Correct |
163 ms |
165268 KB |
Output is correct |
24 |
Correct |
159 ms |
165376 KB |
Output is correct |
25 |
Correct |
155 ms |
165416 KB |
Output is correct |
26 |
Correct |
159 ms |
165212 KB |
Output is correct |
27 |
Correct |
162 ms |
165364 KB |
Output is correct |
28 |
Correct |
156 ms |
165340 KB |
Output is correct |
29 |
Correct |
151 ms |
165368 KB |
Output is correct |
30 |
Correct |
172 ms |
165368 KB |
Output is correct |
31 |
Correct |
151 ms |
165368 KB |
Output is correct |
32 |
Correct |
152 ms |
165368 KB |
Output is correct |
33 |
Correct |
151 ms |
165340 KB |
Output is correct |
34 |
Correct |
150 ms |
165268 KB |
Output is correct |
35 |
Correct |
152 ms |
165496 KB |
Output is correct |
36 |
Correct |
154 ms |
165268 KB |
Output is correct |
37 |
Correct |
150 ms |
165368 KB |
Output is correct |
38 |
Correct |
153 ms |
165372 KB |
Output is correct |
39 |
Correct |
151 ms |
165368 KB |
Output is correct |
40 |
Correct |
154 ms |
165320 KB |
Output is correct |
41 |
Correct |
152 ms |
165240 KB |
Output is correct |
42 |
Correct |
152 ms |
165296 KB |
Output is correct |
43 |
Correct |
152 ms |
165268 KB |
Output is correct |
44 |
Correct |
151 ms |
165296 KB |
Output is correct |
45 |
Correct |
151 ms |
165372 KB |
Output is correct |
46 |
Correct |
152 ms |
165288 KB |
Output is correct |
47 |
Correct |
155 ms |
165368 KB |
Output is correct |
48 |
Correct |
151 ms |
165368 KB |
Output is correct |
49 |
Correct |
151 ms |
165348 KB |
Output is correct |
50 |
Correct |
151 ms |
165368 KB |
Output is correct |
51 |
Correct |
152 ms |
165344 KB |
Output is correct |
52 |
Correct |
151 ms |
165240 KB |
Output is correct |
53 |
Correct |
152 ms |
165340 KB |
Output is correct |
54 |
Correct |
153 ms |
165312 KB |
Output is correct |
55 |
Correct |
159 ms |
174200 KB |
Output is correct |
56 |
Correct |
155 ms |
165316 KB |
Output is correct |
57 |
Correct |
157 ms |
171228 KB |
Output is correct |
58 |
Correct |
802 ms |
169076 KB |
Output is correct |
59 |
Incorrect |
1985 ms |
179580 KB |
Output isn't correct |
60 |
Halted |
0 ms |
0 KB |
- |