QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#519435 | #5416. Fabulous Fungus Frenzy | A6n6d6y6 | TL | 0ms | 3676kb | C++14 | 1.9kb | 2024-08-14 20:13:58 | 2024-08-14 20:13:58 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
char ch[21],c[21][21][21],b[21][21],(&a)[21][21]=c[0];
struct opt{int op,x,y;}g;
vector<opt>ans;map<char,int>cnt;
int h[21],w[21],vis[21][21],&n=h[0],&m=w[0],k;
bool check(int k){
cnt.clear();
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cnt[b[i][j]]++;
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]]--;
else if(cnt['*'])cnt['*']--;
else return 0;
}
}
return 1;
}
void stamp(int k){
memset(vis,0,sizeof vis);
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;l<=n;l++){
if(x||y)break;
for(int r=1;r<=m;r++)
if(!vis[l][r]&&b[l][r]==c[k][i][j]){x=l,y=r;break;}
}
for(int l=1;l<=n;l++){
if(x||y)break;
for(int r=1;r<=m;r++)
if(!vis[l][r]&&b[l][r]=='*'){x=l,y=r;break;}
}
if(!x&&!y){cerr<<"WARNING:BUG on solving "<<k<<"!!!\n";}
while(y<j)swap(b[x][y],b[x][y+1]),ans.push_back({-1,x,y++});
while(y>j)swap(b[x][y],b[x][y-1]),ans.push_back({-2,x,y--});
while(x<i)swap(b[x][y],b[x+1][y]),ans.push_back({-3,x++,y});
while(x>i)swap(b[x][y],b[x-1][y]),ans.push_back({-4,x--,y});
vis[i][j]=1;
}
}
for(int i=1;i<=h[k];i++)
for(int j=1;j<=w[k];j++)
b[i][j]='*';
if(k)ans.push_back({k,1,1});
}
bool solve(){
for(int i=1;i<=k;i++)
if(check(i)){stamp(i);return 1;}
return 0;
}
int main(){
cin>>n>>m>>k;
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>a[i][j];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
cin>>b[i][j];
for(int i=1;i<=k;i++){
cin>>h[i]>>w[i];
for(int j=1;j<=h[i];j++)
for(int l=1;l<=w[i];l++)
cin>>c[i][j][l];
}
while(!check(0)){
if(!solve()){
cout<<"-1\n";
return 0;
}
}stamp(0);
reverse(ans.begin(),ans.end());
cout<<ans.size()<<'\n';
for(auto [op,x,y]:ans)
cout<<op<<' '<<x<<' '<<y<<'\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3648kb
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: 3676kb
input:
2 2 1 OO OO PP PP 1 2 OP
output:
-1
result:
ok puzzle solved
Test #3:
score: -100
Time Limit Exceeded
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