QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#520818 | #5416. Fabulous Fungus Frenzy | wy2025 | WA | 0ms | 3860kb | C++14 | 2.5kb | 2024-08-15 16:04:40 | 2024-08-15 16:04:41 |
Judging History
answer
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=22;
int n[N],m[N],k,a[N][N],now[64],mp[N][N][N],cnt[N][64],uy[64];
bool vis[N][N];
char op;
struct out{int op,x,y;};
stack<out> ans;
int to_int(char x){
if(isdigit(x)) return x-'0'+1;
if(x>='a'&&x<='z') return x-'a'+11;
return x-'A'+37;
}
bool ck(int o){
int ned=0;
for(int i=1;i<63;i++)
ned+=max(0,cnt[o][i]-now[i]);
return (!o||ned!=n[o]*m[o])&&now[63]>=ned;
}
void go(int sx,int sy,int ex,int ey){
while(sx<ex) swap(a[sx][sy],a[sx+1][sy]),ans.push({-3,sx,sy}),sx++;
while(sy<ey) swap(a[sx][sy],a[sx][sy+1]),ans.push({-1,sx,sy}),sy++;
while(sx>ex) swap(a[sx][sy],a[sx-1][sy]),ans.push({-4,sx,sy}),sx--;
while(sy>ey) swap(a[sx][sy],a[sx][sy-1]),ans.push({-2,sx,sy}),sy--;
// cout<<sx<<" "<<sy<<" "<<ex<<" "<<ey<<"\n";
}
void put(int o){
for(int i=1;i<63;i++) uy[i]=min(cnt[o][i],now[i]);
for(int i=1;i<=n[o];i++){
for(int j=1;j<=m[o];j++){
if(!uy[mp[o][i][j]]&&a[i][j]==63) continue;
if(a[i][j]==mp[o][i][j]){uy[a[i][j]]--;continue;}
bool f=0;
for(int x=1;x<=n[0];x++){
for(int y=1;y<=m[0];y++){
if(vis[x][y]) continue;
// cout<<x<<" "<<y<<" "<<a[x][y]<<" "<<i<<" "<<j<<" "<<mp[o][i][j]<<"\n";
if(a[x][y]==mp[o][i][j]){go(x,y,i,j),uy[a[x][y]]--,f=1;break;}
if(a[x][y]==63&&!uy[mp[o][i][j]]){go(x,y,i,j),f=1;break;}
}
if(f) break;
}
now[a[i][j]]--,now[63]++;
a[i][j]=63,vis[i][j]=1;
}
}
for(int i=1;i<=n[o];i++)
for(int j=1;j<=m[o];j++) vis[i][j]=0;
// cout<<n[o]<<" "<<m[o]<<"\n";
// for(int i=1;i<=n[0];i++,cout<<"\n")
// for(int j=1;j<=m[0];j++) cout<<a[i][j]<<" ";
// cout<<"\n\n";
if(o) ans.push({o,1,1});
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);{
cin>>n[0]>>m[0]>>k;
for(int i=1;i<=n[0];i++)
for(int j=1;j<=m[0];j++)
cin>>op,mp[0][i][j]=to_int(op),cnt[0][mp[0][i][j]]++;
for(int i=1;i<=n[0];i++)
for(int j=1;j<=m[0];j++)
cin>>op,a[i][j]=to_int(op),now[a[i][j]]++;
for(int o=1;o<=k;o++){
cin>>n[o]>>m[o];
for(int i=1;i<=n[o];i++)
for(int j=1;j<=m[o];j++)
cin>>op,mp[o][i][j]=to_int(op),cnt[o][mp[o][i][j]]++;
}
}
while(!ck(0)){
bool f=0;
for(int i=1;i<=k;i++)
if(ck(i)) put(i),f=1;
if(!f) cout<<-1,exit(0);
}
put(0);
cout<<ans.size()<<"\n";
while(!ans.empty()) cout<<ans.top().op<<" "<<ans.top().x<<" "<<ans.top().y<<"\n",ans.pop();
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: 3860kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
12 -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:
wrong answer puzzle remain unsolved