Gym - 102411K
King's Children
Gym - 102411K
https://vjudge.net/problem/Gym-102411K/origin
这个题就很贼了,思路是先填'A',填到最大,然后再填充其他的,不同的顺序会影响结果,经过wa42,wa40,wa46,我们AC了
//队友代码 #include <bits/stdc++.h> #define inf 2333333333333333 #define N 1000010 #define p(a) putchar(a) #define For(i,a,b) for(int i=a;i<=b;++i) using namespace std; char G[1010][1010]; int n,m; int l[1010]; int r[1010]; int getarea(int i,int j){ return (min(l[i],l[j])+min(r[i],r[j])+1)*(j-i+1); } void cal(int ax,int ay,char c1){//j i char c2=c1-'A'+'a'; for(int i=1;i<=n;i++)l[i]=0,r[i]=0; for(int i=ay;i<=n;i++){ if(i!=ay&&G[i][ax]!='.')break; for(int j=ax+1;j<=m;j++){ if(G[i][j]=='.'){ r[i]++; }else break; } if(i!=ay)r[i]=min(r[i],r[i-1]); } for(int i=ay;i<=n;i++){ if(i!=ay&&G[i][ax]!='.')break; for(int j=ax-1;j>=1;j--){ if(G[i][j]=='.'){ l[i]++; }else break; } if(i!=ay)l[i]=min(l[i],l[i-1]); } for(int i=ay-1;i>=1;i--){ if(i!=ay&&G[i][ax]!='.')break; for(int j=ax+1;j<=m;j++){ if(G[i][j]=='.'){ r[i]++; }else break; } if(i!=ay)r[i]=min(r[i],r[i+1]); } for(int i=ay-1;i>=1;i--){ if(i!=ay&&G[i][ax]!='.')break; for(int j=ax-1;j>=1;j--){ if(G[i][j]=='.'){ l[i]++; }else break; } if(i!=ay)l[i]=min(l[i],l[i+1]); } int ansup=0,ansdown=0; ansup=ansdown=ay; for(int i=ay;i>=1;i--){ if(i!=ay&&G[i][ax]!='.')break; for(int j=ay;j<=n;j++){ if(j!=ay&&G[j][ax]!='.')break; if(getarea(i,j)>getarea(ansdown,ansup)){ ansdown=i; ansup=j; } } } int ll=min(l[ansup],l[ansdown]),rr=min(r[ansup],r[ansdown]); for(int i=ansdown;i<=ansup;i++){ for(int j=ax-ll;j<=ax+rr;j++){ if(G[i][j]=='.'){ G[i][j]=c2; } } } //for(int i=1;i<=n;i++){cout<<(G[i]+1)<<endl;} } signed main(){ scanf("%d%d",&n,&m); for(int i=1;i<=n;i++){cin>>(G[i]+1);} for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(G[i][j]=='A'){ cal(j,i,'A'); } } } for(int i=n;i>=1;i--){ for(int j=1;j<=m;j++){ if(G[i][j]>'A'&&G[i][j]<='Z'){ cal(j,i,G[i][j]); } } } /* for(int i=1;i<=n;i++){ for(int j=1;j<=m;j++){ if(G[i][j]>'A'&&G[i][j]<='Z'){ color(G[i][j]-'a') } } }*/ for(int i=1;i<=n;i++){cout<<(G[i]+1)<<endl;} return 0; }