QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#520163 | #5416. Fabulous Fungus Frenzy | dczissb | WA | 0ms | 3748kb | C++14 | 2.4kb | 2024-08-15 11:16:10 | 2024-08-15 11:16:10 |
Judging History
answer
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,m,x[21],y[21],vis[21][21];
struct dcz{
int x,y,z;
};
vector<dcz> ans;
int ton[129];
char mp[21][21],z[21][21][21];
int check(int g){
// cout<<g<<endl;
memset(ton,0,sizeof ton);
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
ton[(int)mp[i][j]]++;
}
}
int ans=0;
for(int i=1;i<=x[g];i++){
for(int j=1;j<=y[g];j++){
// cout<<(int)z[g][i][j]<<" ";
if(ton[z[g][i][j]]) ton[z[g][i][j]]--,ans++;
else if(ton['&']) ton['&']--;
else return -1;
}
// cout<<endl;
}
return ans;
}
void solve(int g){
memset(vis,0,sizeof vis);
for(int i=1;i<=x[g];i++){
for(int j=1;j<=y[g];j++){
int p=0,q=0;
for(int l=1;l<=n;l++){
for(int r=1;r<=m;r++){
if(p||q) break;
if(!vis[l][r]&&mp[l][r]==z[g][i][j]){
p=l,q=r;
break;
}
}
if(p||q) break;
}
for(int l=1;l<=n;l++){
for(int r=1;r<=m;r++){
if(p||q) break;
if(!vis[l][r]&&mp[l][r]=='&'){
p=l,q=r;
break;
}
}
if(p||q) break;
}
// cout<<p<<" "<<q<<endl;
while(p<i) swap(mp[p][q],mp[p+1][q]),ans.push_back({-3,p++,q});
while(p>i) swap(mp[p][q],mp[p-1][q]),ans.push_back({-4,p--,q});
while(q<j) swap(mp[p][q],mp[p][q+1]),ans.push_back({-1,p,q++});
while(q>j) swap(mp[p][q],mp[p][q-1]),ans.push_back({-2,p,q--});
vis[p][q]=1;
}
}
for(int i=1;i<=x[g];i++){
for(int j=1;j<=y[g];j++){
mp[i][j]='&';
}
}
if(g) ans.push_back({g,1,1});
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
cin>>n>>m>>k;
x[0]=n,y[0]=m;
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>z[0][i][j];
}
}
for(int i=1;i<=n;i++){
for(int j=1;j<=m;j++){
cin>>mp[i][j];
}
}
for(int o=1;o<=k;o++){
cin>>x[o]>>y[o];
for(int i=1;i<=x[o];i++){
for(int j=1;j<=y[o];j++){
cin>>z[o][i][j];
}
}
}
// for(int o=0;o<=k;o++){
// for(int i=1;i<=x[o];i++){
// for(int j=1;j<=y[o];j++){
// cout<<(int)z[o][i][j]<<" ";
// }
// cout<<endl;
// }
// cout<<endl;
// }
while(check(0)<0){
int f=0;
for(int i=1;i<=k;i++){
if(check(i)>0){f=1;solve(i);}
}
if(!f) cout<<-1,exit(0);
}
solve(0);
cout<<ans.size()<<endl;
reverse(ans.begin(),ans.end());
for(int i=0;i<ans.size();i++){
cout<<ans[i].x<<" "<<ans[i].y<<" "<<ans[i].z<<endl;
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3748kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
22 -1 3 2 -1 3 1 -1 3 0 -3 2 0 -3 1 0 -3 0 0 -2 3 2 -2 3 3 -1 2 2 -4 3 2 -2 2 3 -2 2 2 -2 2 3 -1 1 2 -4 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 Integer parameter [name=y_2] equals to 0, violates the range [1, 3]