QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#520765 | #5416. Fabulous Fungus Frenzy | z | WA | 2ms | 4068kb | C++14 | 2.3kb | 2024-08-15 15:28:49 | 2024-08-15 15:28:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int N=22,M=100;
char S[N];
int step;
int n,m,k;
int s[N][N][N];
int a[N][N];
int h[N],w[N];
int col[M];
struct Opt{
int op,x,y;
}O[400005];
int trans(char c){
if(c>96) return c-86;
if(c>64) return c-28;
return c-47;
}
bool check2(int x){
for(int i=1;i<=h[x];i++) for(int j=1;j<=w[x];j++)
if(a[i][j]!=s[x][i][j]) return 0;
return 1;
}
bool check(int x){
//if(check2(x)) return 0;
for(int i=0;i<=62;i++) col[i]=0;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) col[a[i][j]]++;
for(int i=1;i<=h[x];i++)
for(int j=1;j<=w[x];j++){
if(col[s[x][i][j]]) --col[s[x][i][j]];
else if(col[0]) --col[0];
else return 0;
}
return 1;
}
char tr(int x){
if(x<11) return x+47;
if(x<37) return x+86;
return x+28;
}
void solve(int now){
for(int i=1;i<=h[now];i++){
for(int j=1;j<=w[now];j++){
int x=0,y=0;
for(int p=1;!x&&p<=n;p++) for(int q=1;!x&&q<=m;q++)
if((p>i||p<i&&q>w[x]||p==i&&q>=j)&&a[p][q]==s[now][i][j]) x=p,y=q;
for(int p=1;!x&&p<=n;p++) for(int q=1;!x&&q<=m;q++)
if((p>i||p<i&&q>w[x]||p==i&&q>=j)&&a[p][q]==0) x=p,y=q;
//下左右上
while(x<i) swap(a[x][y],a[x+1][y]),O[++step]={-3,x,y},++x;
while(y>j) swap(a[x][y],a[x][y-1]),O[++step]={-2,x,y},--y;
while(y<j) swap(a[x][y],a[x][y+1]),O[++step]={-1,x,y},++y;
while(x>i) swap(a[x][y],a[x-1][y]),O[++step]={-4,x,y},--x;
a[i][j]=0;
}
}
O[++step]={now,1,1};
}
int main(){
scanf("%d%d%d",&n,&m,&k);
h[0]=n,w[0]=m;
for(int i=1;i<=n;i++){
scanf("%s",S+1);
for(int j=1;j<=m;j++)
s[0][i][j]=trans(S[j]);
}
for(int i=1;i<=n;i++){
scanf("%s",S+1);
for(int j=1;j<=m;j++)
a[i][j]=trans(S[j]);
}
for(int l=1;l<=k;l++){
scanf("%d%d",&h[l],&w[l]);
for(int i=1;i<=h[l];i++){
scanf("%s",S+1);
for(int j=1;j<=w[l];j++)
s[l][i][j]=trans(S[j]);
}
}
while(1){
bool f=1;
if(check(0)) break;
for(int i=1;i<=k;i++){
if(check(i)){
solve(i);
f=0;
}
}
if(f){
puts("-1");
return 0;
}
}
solve(0);
printf("%d\n",step-1);
for(int i=step-1;i;i--) printf("%d %d %d\n",O[i].op,O[i].x,O[i].y);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3808kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
13 -2 3 2 -4 3 3 -1 3 2 -2 2 2 -4 2 3 -1 2 2 -2 1 3 -2 1 2 1 1 1 -2 3 2 -2 2 2 -4 2 1 -4 3 1
result:
ok puzzle solved
Test #2:
score: 0
Accepted
time: 0ms
memory: 3856kb
input:
2 2 1 OO OO PP PP 1 2 OP
output:
-1
result:
ok puzzle solved
Test #3:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
4 8 4 11122222 33344444 55556666 77777777 NIxSHUOx DExDUIxx DANxSHIx YUANSHEN 2 3 NIy DEx 3 8 zzzzzzzz DANNSH9I YUA9SHEN 1 1 x 2 5 SHO8y DUUI8
output:
168 4 1 1 3 1 1 -4 2 1 -4 3 1 -4 4 1 -2 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 2 1 1 1 1 1 -4 3 3 -4 4 3 -2 4 4 -2 4 5 -2 4 6 4 1 1 3 1 1 -4 2 1 -4 3 1 -4 4 1 -2 4 2 -2 4 3 -2 4 4 2 1 1 -4 4 8 -1 4 7 -1 4 6 -1 4 5 -1 4 4 -1 4 3 -1 4 2 -1 4 1 -4 4 7 -1 4 6 -1 4 5 -1 4 4 -1 4 3 -1 4 2 -1 4 1 -4...
result:
ok puzzle solved
Test #4:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
2 2 1 OO OO OP PP 1 2 PP
output:
8 -4 2 1 -2 2 2 1 1 1 -4 2 1 1 1 1 -4 2 2 -1 2 1 -2 1 2
result:
ok puzzle solved
Test #5:
score: 0
Accepted
time: 0ms
memory: 3940kb
input:
2 2 1 OO OO OP PO 2 1 P P
output:
4 -4 2 2 -2 1 2 1 1 1 -2 1 2
result:
ok puzzle solved
Test #6:
score: 0
Accepted
time: 0ms
memory: 3756kb
input:
2 2 1 OO OO OP PO 2 2 PP PP
output:
-1
result:
ok puzzle solved
Test #7:
score: 0
Accepted
time: 0ms
memory: 3932kb
input:
2 2 1 OO OO OP PP 1 2 OP
output:
7 1 1 1 -4 2 2 -1 2 1 1 1 1 -4 2 2 -1 2 1 1 1 1
result:
ok puzzle solved
Test #8:
score: -100
Wrong Answer
time: 2ms
memory: 4068kb
input:
20 20 20 bofelagiqboebdqplbhq qsrksfthhptcmikjohkt qrnhpoatbekggnkdonet aoalekbmpbisgflbhmol djnhnlitcakltqgegqrt fdctfarsmbnbeosdgilo ttrsljgiratfmioajorh gorljkihdnmnofnblfhm bqjkaehetdjlgctmijpc geslcskpoqjcgtbdspoa riqthroqmmhqgprqhsba fdiarrcomockfqdjjdkd jsbnigfqgsfekbbnnkir ildqctqtqrpcetaocp...
output:
9854 20 1 1 19 1 1 18 1 1 17 1 1 16 1 1 15 1 1 14 1 1 13 1 1 12 1 1 11 1 1 10 1 1 9 1 1 8 1 1 -4 2 1 -4 3 1 -4 4 1 -4 5 1 -4 6 1 -4 7 1 -4 8 1 -4 9 1 -4 10 1 -4 11 1 -4 12 1 -4 13 1 -4 14 1 -4 15 1 -4 16 1 -4 17 1 -4 18 1 -4 19 1 -4 20 1 -2 20 2 -2 20 3 -2 20 4 -2 20 5 -2 20 6 -2 20 7 -2 20 8 -2 20 ...
result:
wrong answer preset op exceed 400