QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471309 | #5416. Fabulous Fungus Frenzy | maojun | WA | 0ms | 3912kb | C++23 | 1.9kb | 2024-07-10 20:28:15 | 2024-07-10 20:28:16 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
const int S=25,V=125;
int N,M,K;char a[S][S];int hv[V];
vector<tuple<int,int,int>>ans;
#define eb emplace_back
inline void mov(int x,int y,int X,int Y){
for(;y>Y;y--){swap(a[x][y],a[x][y-1]);ans.eb(-2,x,y);}
for(;y<Y;y++){swap(a[x][y],a[x][y+1]);ans.eb(-1,x,y);}
for(;x>X;x--){swap(a[x][y],a[x-1][y]);ans.eb(-4,x,y);}
for(;x<X;x++){swap(a[x][y],a[x+1][y]);ans.eb(-3,x,y);}
}
int n[S],m[S];char b[S][S][S];int nd[S][V];
inline void rd(int o){for(int i=1;i<=n[o];i++){scanf("%s",b[o][i]+1);for(int j=1;j<=m[o];j++)nd[o][b[o][i][j]]++;}}
int star;
inline int ndStar(int o){int r=0;for(int i=0;i<V;i++)r+=max(0,nd[o][i]-hv[i]);return r;}
inline bool mkStar(int o){for(int i=0;i<V;i++)if(nd[o][i]&&hv[i])return true;return false;}
inline void Mov(char c,int X,int Y,int o){
for(int i=1;i<=N;i++)for(int j=1;j<=M;j++)
if(!((i<X&&j<=m[o])||(i==X&&j<Y))&&a[i][j]==c){mov(i,j,X,Y);break;}
}
inline void press(int o){for(int i=1;i<=n[o];i++)for(int j=1;j<=m[o];j++)a[i][j]='*';ans.eb(o,1,1);}
inline void pOld(int o){
for(int i=1;i<=n[o];i++)for(int j=1;j<=m[o];j++)if(int c=b[o][i][j];hv[c]){
Mov(c,i,j,o);star++;hv[c]--;
return press(o);
}
}
inline void pNew(int o){
for(int i=1;i<=n[o];i++)for(int j=1;j<=m[o];j++)
if(int c=b[o][i][j];hv[c]){
Mov(c,i,j,o);star++;hv[c]--;
}else Mov('*',i,j,o);
press(o);
}
int main(){
scanf("%d%d%d",&N,&M,&K);n[0]=N;m[0]=M;rd(0);
for(int i=1;i<=N;i++){scanf("%s",a[i]+1);for(int j=1;j<=M;j++)hv[a[i][j]]++;}
for(int i=1;i<=K;i++){scanf("%d%d",&n[i],&m[i]);rd(i);}
for(int o=0;true;)
if(o&&mkStar(o)&&star>=ndStar(o))pOld(o);
else{
for(o=1;o<=K;o++)if(mkStar(o)&&star>=ndStar(o)){pNew(o);break;}
if(o>K)break;
}
if(star<ndStar(0)){puts("-1");return 0;}
if(mkStar(0)){pNew(0);ans.pop_back();}
printf("%d\n",ans.size());reverse(ans.begin(),ans.end());
for(auto[o,x,y]:ans)printf("%d %d %d\n",o,x,y);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3912kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
33 -4 3 3 -1 3 2 -1 3 1 -4 3 2 -1 3 1 -4 3 1 -4 2 3 -1 2 2 -4 2 2 -1 2 1 -2 1 3 -4 2 1 -2 2 2 -2 2 3 -2 1 2 1 1 1 1 1 1 -4 3 1 -2 3 2 -2 3 3 -2 2 2 -2 2 3 1 1 1 -4 2 1 -4 3 1 -2 3 2 -2 3 3 1 1 1 -2 3 2 -4 3 1 -2 2 2 -4 2 1 -4 3 1
result:
wrong answer puzzle remain unsolved