QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#510571 | #5416. Fabulous Fungus Frenzy | xiahaob | WA | 0ms | 3900kb | C++14 | 2.3kb | 2024-08-09 09:22:59 | 2024-08-09 09:22:59 |
Judging History
answer
#include<bits/stdc++.h>
#define eb(a,b,c) emplace_back(a,b,c)
using namespace std;
inline int rd(){
int s=0,w=1;char ch=getchar();
for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')w=-1;
for(;ch>='0'&&ch<='9';ch=getchar())s=s*10+ch-'0';
return s*w;
}
char FF[100];
int n[100],m[100],k;
int S[100][100][100],T[100][100],cs[100][100],ct[100];
vector<tuple<int,int,int> > opt;
inline int STR(char ch){
if(isdigit(ch))return ch-'0';
if(islower(ch))return 10+ch-'a';
return 36+ch-'A';
}
inline void TO(int x,int y,int a,int b,int id){//s,t
if(x==a&&y==b)return;
for(;y<m[id];++y)opt.eb(-2,x,y+1),swap(T[x][y],T[x][y+1]);
for(;y>m[id];--y)opt.eb(-1,x,y-1),swap(T[x][y],T[x][y-1]);
for(;x>a;--x)opt.eb(-3,x-1,y),swap(T[x][y],T[x-1][y]);
for(;x<a;++x)opt.eb(-4,x+1,y),swap(T[x][y],T[x+1][y]);
for(;y>b;--y)opt.eb(-1,x,y-1),swap(T[x][y],T[x][y-1]);
}
double st;
inline bool rev(int id){
int sm=0;
for(int i=0;i<62;++i)sm+=min(cs[id][i],ct[i]);
if(sm+ct[62]<n[id]*m[id]||(!sm&&id))return 0;
for(int i=1;i<=n[id];++i){
for(int j=1;j<=m[id];++j){
int x=0,y=0;
for(int a=i;a<=n[0];++a){
for(int b=a<i?m[id]+1:(a==i?j:1);b<=m[0];++b)if(S[id][i][j]==T[a][b]){x=a;y=b;break;}
if(x)break;
}
if(!x){
for(int a=i;a<=n[0];++a){
for(int b=a<i?m[id]+1:(a==i?j:1);b<=m[0];++b)if(T[a][b]==62){x=a;y=b;break;}
if(x)break;
}
}
printf("%d %d %d %d \n",x,y,i,j);
TO(x,y,i,j,id);
}
}
if(id)opt.eb(id,1,1);
for(int i=1;i<=n[id];++i)for(int j=1;j<=m[id];++j)ct[T[i][j]]--,ct[T[i][j]=62]++;
return 1;
}
int main(){
st=clock();
n[0]=rd();m[0]=rd();k=rd();
for(int i=1;i<=n[0];++i){
scanf("%s",FF+1);
for(int j=1;j<=m[0];++j)S[0][i][j]=STR(FF[j]),cs[0][S[0][i][j]]++;
}
for(int i=1;i<=n[0];++i){
scanf("%s",FF+1);
for(int j=1;j<=m[0];++j)T[i][j]=STR(FF[j]),ct[T[i][j]]++;
}
for(int z=1;z<=k;++z){
n[z]=rd();m[z]=rd();
for(int i=1;i<=n[z];++i){
scanf("%s",FF+1);
for(int j=1;j<=m[z];++j)S[z][i][j]=STR(FF[j]),cs[z][S[z][i][j]]++;
}
}
while(1){
bool flag=0;
for(int i=1;i<=k;++i)flag|=rev(i);
if(!flag)break;
}
if(!rev(0))return puts("-1"),0;
reverse(opt.begin(),opt.end());
printf("%d\n",opt.size());
for(auto [x,y,z]:opt)printf("%d %d %d\n",x,y,z);
return 0;
}
/*
3 3 1
OOO
GOG
BGB
OOO
GGG
BBB
3 1
B
G
B
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3900kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
3 1 1 1 2 2 2 1 3 2 3 1 3 3 1 1 2 3 2 1 3 1 3 1 1 1 1 1 3 3 2 1 3 1 3 1 1 2 1 1 1 3 1 2 2 3 1 3 2 1 2 1 2 2 2 2 2 3 2 3 3 1 3 1 3 2 3 2 3 3 3 3 21 -3 1 3 -1 1 2 -1 1 1 -1 1 2 -2 1 3 1 1 1 -3 2 1 -1 3 1 -1 3 2 1 1 1 -1 2 1 -1 2 2 -3 1 1 -3 2 1 -1 3 1 -1 3 2 1 1 1 -1 3 1 -1 2 1 -3 1 ...
result:
wrong answer Integer parameter [name=op_1] equals to 2, violates the range [-4, 1]