QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471396 | #5416. Fabulous Fungus Frenzy | zyxawa | WA | 0ms | 3892kb | C++23 | 2.1kb | 2024-07-10 20:54:48 | 2024-07-10 20:54:49 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define trans(c) (isdigit(c)?c-48:(islower(c)?c-87:c-29))
char ch[21];
vector <tuple<int,int,int>> ans;
int n,m,k,a[21][21],c[21][21][21],h[21],w[21],cnt[63],v[21][21];
int check(int k){
memset(cnt,0,sizeof(cnt));
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cnt[a[i][j]]++;
int res=0;
for(int i=1;i<=h[k];i++){
for(int j=1;j<=w[k];j++){
if(cnt[c[k][i][j]]) cnt[c[k][i][j]]--,res++;
else if(cnt[0]) cnt[0]--;
else return -1;
}
}
return res;
}
void solve(int k){
if(check(k)<=0){
if(1){
printf("joker\n");
}
}
memset(v,0,sizeof(v));
for(int i=1;i<=h[k];i++){
for(int j=1;j<=w[k];j++){
int x=0,y=0;
for(int l=1;!x&&l<=n;l++) for(int r=1;r<=m;r++) if(!v[l][r]&&a[l][r]==c[k][i][j]) x=l,y=r;
for(int l=1;!x&&l<=n;l++) for(int r=1;r<=m;r++) if(!v[l][r]&&!a[l][r]) x=l,y=r;
while(x<i) swap(a[x][y],a[x+1][y]),ans.push_back({-3,x++,y});
while(y<j) swap(a[x][y],a[x][y+1]),ans.push_back({-1,x,y++});
while(x>i) swap(a[x][y],a[x-1][y]),ans.push_back({-4,x--,y});
while(y>j) swap(a[x][y],a[x][y-1]),ans.push_back({-2,x,y--});
v[i][j]=1;
}
}
int f=0;
for(int i=1;i<=h[k];i++){
for(int j=1;j<=w[k];j++){
f|=a[i][j]!=0;
}
}
if(!f&&k){
if(1){
cout<<"SB\n";
}
}
for(int i=1;i<=h[k];i++) for(int j=1;j<=w[k];j++) a[i][j]=0;
if(k) ans.push_back({k,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",ch+1);
for(int j=1;j<=m;j++) c[0][i][j]=trans(ch[j]);
}
for(int i=1;i<=n;i++){
scanf("%s",ch+1);
for(int j=1;j<=m;j++) a[i][j]=trans(ch[j]);
}
for(int i=1;i<=k;i++){
scanf("%d%d",&h[i],&w[i]);
for(int j=1;j<=h[i];j++){
scanf("%s",ch+1);
for(int l=1;l<=w[i];l++) c[i][j][l]=trans(ch[l]);
}
}
while(1){
if(check(0)>=0) break;
int f=0;
for(int i=1;i<=k;i++) if(check(i)>0) f=1,solve(i);
if(!f) return printf("-1"),0;
}
solve(0);
reverse(begin(ans),end(ans));
printf("%d\n",ans.size());
for(auto [a,b,c]:ans) printf("%d %d %d\n",a,b,c);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3892kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
16 -2 3 3 -2 3 2 -4 3 3 -2 2 3 -2 2 2 -4 2 3 -2 1 3 -2 1 2 -2 1 3 1 1 1 -2 3 2 -2 2 2 -2 1 2 -2 1 3 -4 2 3 -4 3 3
result:
ok puzzle solved
Test #2:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
2 2 1 OO OO PP PP 1 2 OP
output:
-1
result:
ok puzzle solved
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3808kb
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:
joker 311 -2 4 8 -2 4 7 -2 4 8 -2 4 6 -2 4 7 -2 4 8 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -2 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -2 3 8 -2 3 7 -2 3 8 -2 3 6 -2 3 7 -2 3 8 -2 3 5 -2 3 6 -2 3 7 -2 3 8 -2 3 4 -2 3 5 -2 3 6 -2 ...
result:
wrong output format Expected integer, but "joker" found