QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471854 | #5416. Fabulous Fungus Frenzy | DEMONKILLER | RE | 0ms | 0kb | C++14 | 3.1kb | 2024-07-11 10:12:25 | 2024-07-11 10:12:25 |
answer
#include<bits/stdc++.h>
#define N 25
#define M 210
using namespace std;
struct node{
int opt,x,y;
};
int n,m,k,sk,f[N],c[M],kn[N],km[N],num[N][M];
char ed[N][N],p[N][N][N];
vector<node> ans;
int to(char c){
if(c=='#')return 0;
if(c>='0'&&c<='9')return c-'0'+1;
if(c>='a'&&c<='z')return c-'a'+11;
if(c>='A'&&c<='Z')return c-'A'+37;
}
void mov(int x,int y,int tx,int ty){
while(x<tx)swap(ed[x][y],ed[x+1][y]),ans.push_back((node){-3,x,y}),x++;
while(y<ty)swap(ed[x][y],ed[x][y+1]),ans.push_back((node){-1,x,y}),y++;
while(y>ty)swap(ed[x][y],ed[x][y-1]),ans.push_back((node){-2,x,y}),y--;
while(x>tx)swap(ed[x][y],ed[x-1][y]),ans.push_back((node){-4,x,y}),x--;
}
int main(){
scanf("%d%d%d",&n,&m,&k);
for(int i=1;i<=n;i++){
scanf("%s",p[0][i]+1);
for(int j=1;j<=m;j++){
num[0][to(p[0][i][j])]++;
}
}
for(int i=1;i<=n;i++){
scanf("%s",ed[i]+1);
for(int j=1;j<=m;j++){
c[to(ed[i][j])]++;
}
}
kn[0]=n,km[0]=m;
for(int i=1;i<=k;i++){
scanf("%d%d",&kn[i],&km[i]);
for(int x=1;x<=kn[i];x++){
scanf("%s",p[i][x]+1);
for(int y=1;y<=km[i];y++)
num[i][to(p[i][x][y])]++;
}
}
for(int d=0;d<=k;d++){
for(int x=0;x<=k;x++){
int cnt=0;
for(int i=1;i<=62;i++){
f[i]=max(0,num[x][i]-c[i]);
cnt+=f[i];
}
while(cnt<=sk&&cnt<kn[x]*km[x]){
for(int i=1;i<=kn[x];i++)
for(int j=1;j<=km[x];j++){
int now=to(p[x][i][j]);
if(f[now])f[now]--,now=0;
if(to(ed[i][j])!=now){
bool flag=false;
for(int ii=1;ii<=n;ii++){
for(int jj=1;jj<=m;jj++)
if(!((ii<i&&jj<=km[x])||(ii==i&&jj<j))&&to(ed[ii][jj])==now){
mov(ii,jj,i,j);
flag=true;
break;
}
if(flag)break;
}
}
}
for(int i=1;i<=kn[x];i++)
for(int j=1;j<=km[x];j++)
if(to(ed[i][j])){
c[to(ed[i][j])]--;
sk++;
ed[i][j]='#';
}
ans.push_back((node){x,1,1});
cnt=0;
for(int i=1;i<=62;i++){
f[i]=max(0,num[x][i]-c[i]);
cnt+=f[i];
}
}
if(sk==n*m){
if(!ans[ans.size()-1].opt)ans.pop_back();
reverse(ans.begin(),ans.end());
printf("%d\n",ans.size());
for(auto i:ans)printf("%d %d %d\n",i.opt,i.x,i.y);
return 0;
}
}
}
puts("-1");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Runtime Error
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B