#include #include #include #include #include #define REP(i,a,b) for(i=a;i= x || nj >= y) continue; assert(!(in[ci][nj]!='P' && in[ni][nj]=='G')); if(in[ci][cj]!='P' && in[ni][nj]=='F') in[ni][nj] = 'D'; /* this place is not available */ } } } rep(di, 2) rep(dj, 2){ /* consider the cells (i mod 2, j mod 2) = (di, dj) */ N1 = N2 = 0; /* N1 = the number of left nodes, N2 = right nodes */ for(i=di ;i= x || nj >= y) continue; if(in[ci][cj]!='P' && in[ni][nj]=='F'){ l = num[i][j]; m = N1 + num[ni][nj]; edge[l][es[l]++] = m; } } } res += N1+N2 - MaxMatch(); } printf("%d\n",res); } return 0; }