1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
| const int N=510,M=N*N/2,INF=1e9+10; const char infile[]="5.in",outfile[]="output_05.txt"; const int MAX=48620;
int n,m,C; char s[N][N]; int chk(char x){ return x=='P' || x=='G'; } struct Node{ int x,y,t; } R[M]; bitset <M> Ansmap,Nowmap; int ans,now;
int z[4][2]={ {0,1},{1,0},{-1,-1},{-1,1} }; char S[]="-|\\/"; vector <int> G[N][N],E[M];
struct Naive_Simulator{ ~Naive_Simulator(){ cerr<<"!"<<endl; rep(i,1,C) if(Ansmap[i]) s[R[i].x][R[i].y]=S[R[i].t]; rep(i,1,n) puts(s[i]+1); } int P[M],D[M],F[M],PC,counter,lst,L; void Work(db T,db d,db End,int delta) { while(T>End && ans<MAX) { if(++counter%4000==0) { cerr<<ans<<' '<<T<<endl; } if(counter%500==0) random_shuffle(D+1,D+C+1),lst=1; PC=0; rep(i,lst,C) if(!Nowmap[D[i]]) { P[++PC]=D[i]; lst=i; if(PC>=L) break; } if(PC<L) { lst=1; PC=0; rep(i,lst,C) if(!Nowmap[D[i]]) { P[++PC]=D[i]; lst=i; if(PC>=L) break; } } rep(kase,1,50) { int u,v; u=P[rand()%PC+1],v=P[rand()%PC+1]; if(u==v || Nowmap[u]) { kase--; continue; } int cnt=0; for(int v:E[u]) cnt+=Nowmap[v]; if(cnt-delta<=T) { Nowmap[u]=1; for(int v:E[u]) Nowmap[v]=0; now+=1-cnt; } if(kase%5==0 && now>ans) ans=now,Ansmap=Nowmap; } T*=d; } } void Simulate(){ srand(time(NULL)); now=0,Nowmap.reset(); counter=0,lst=1,L=200; rep(i,1,C) D[i]=i; rep(kase,1,10) Work(2,0.95,1e-2,1); Work(0.99,0.99993,1e-8,2); Nowmap=Ansmap,now=ans; Work(0.99,0.99999,0,1); return; }
Naive_Simulator(){ freopen(infile,"r",stdin),freopen(outfile,"w",stdout); n=rd(),m=rd(); rep(i,1,n) scanf("%s",s[i]+1); rep(i,1,n) rep(j,1,m) if(!chk(s[i][j])) { s[i][j]='W'; rep(d,0,3) if(chk(s[i+z[d][0]][j+z[d][1]]) && chk(s[i-z[d][0]][j-z[d][1]]) && s[i+z[d][0]][j+z[d][1]]!=s[i-z[d][0]][j-z[d][1]]) { R[++C]=(Node){i,j,d}; G[i][j].pb(C); G[i+z[d][0]][j+z[d][1]].pb(C); G[i-z[d][0]][j-z[d][1]].pb(C); } } rep(i,1,n) rep(j,1,m) rep(k,0,G[i][j].size()-1) rep(l,k+1,kend) { E[G[i][j][k]].pb(G[i][j][l]); E[G[i][j][l]].pb(G[i][j][k]); } Simulate(); } } Solver;
int main(){ ; }
|