QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#520884 | #5416. Fabulous Fungus Frenzy | q | WA | 0ms | 3704kb | C++23 | 2.4kb | 2024-08-15 17:09:14 | 2024-08-15 17:09:14 |
Judging History
answer
#include<bits/stdc++.h>
const int N=25;
int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N];
std::vector<std::tuple<int,int,int> > ans;
inline void get_mp(){
int tot=0;
for(char i='0';i<='9';i++) mp[(int)i]=++tot;
for(char i='a';i<='z';i++) mp[(int)i]=++tot;
for(char i='A';i<='Z';i++) mp[(int)i]=++tot;
}
inline int chk(int k){
static int cnt[N]; memset(cnt,0,sizeof cnt);
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cnt[a[i][j]]++;
int tot=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]]--,tot++;
else if(cnt[0]) cnt[0]--;
else return -1;
}
return tot;
}
inline void work(int k){
static bool vis[N][N]; memset(vis,false,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++) for(int o=1;o<=m;o++) if(!vis[l][o]&&a[l][o]==c[k][i][j]){ x=l,y=o; break; }
if(!x) for(int l=1;l<=n;l++) for(int o=1;o<=m;o++) if(!vis[l][o]&&!a[l][o]){ x=l,y=o; break; }
for(;x<i;x++) std::swap(a[x][y],a[x+1][y]),ans.push_back(std::make_tuple(-3,x,y));
for(;y<j;y++) std::swap(a[x][y],a[x][y+1]),ans.push_back(std::make_tuple(-1,x,y));
for(;x>i;x--) std::swap(a[x][y],a[x-1][y]),ans.push_back(std::make_tuple(-4,x,y));
for(;y>j;y--) std::swap(a[x][y],a[x][y-1]),ans.push_back(std::make_tuple(-2,x,y));
vis[i][j]=true;
}
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(std::make_tuple(k,1,1));
}
int main(){
std::ios::sync_with_stdio(false),std::cin.tie(nullptr),std::cout.tie(nullptr);
get_mp();
std::cin>>n>>m>>k,h[0]=n,w[0]=m;
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ char ch; std::cin>>ch; c[0][i][j]=mp[(int)ch]; }
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++){ char ch; std::cin>>ch; a[i][j]=mp[(int)ch]; }
for(int i=1;i<=k;i++){
std::cin>>h[i]>>w[i];
for(int j=1;j<=h[i];j++) for(int l=1;l<=w[i];l++){ char ch; std::cin>>ch; c[i][j][l]=mp[(int)ch]; }
}
for(;chk(0)<0;){
bool flag=false;
for(int i=1;i<=k;i++) if(chk(i)>0) flag=true,work(i);
if(!flag) return std::cout<<-1,0;
}
work(0);
std::reverse(ans.begin(),ans.end());
std::cout<<ans.size()<<"\n";
for(auto [op,x,y]:ans) std::cout<<op<<" "<<x<<" "<<y<<"\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3700kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
15 -2 3 2 -2 3 3 -4 3 2 -1 3 1 -2 2 2 -4 3 2 -4 2 2 -2 1 2 -4 2 2 -4 3 2 1 1 1 -2 3 2 -4 3 1 -4 2 1 -4 3 1
result:
ok puzzle solved
Test #2:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
2 2 1 OO OO PP PP 1 2 OP
output:
-1
result:
ok puzzle solved
Test #3:
score: 0
Accepted
time: 0ms
memory: 3660kb
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:
607 -4 4 8 -1 4 7 -1 4 6 -1 4 5 -1 4 4 -1 4 3 -1 4 2 -1 4 1 -4 4 7 -1 4 6 -1 4 5 -1 4 4 -1 4 3 -1 4 2 -1 4 1 -4 4 6 -1 4 5 -1 4 4 -1 4 3 -1 4 2 -1 4 1 -4 4 5 -1 4 4 -1 4 3 -1 4 2 -1 4 1 -4 4 4 -1 4 3 -1 4 2 -1 4 1 -4 4 3 -1 4 2 -1 4 1 -4 4 2 -1 4 1 -4 4 1 -4 3 8 -4 4 8 -1 4 7 -1 4 6 -1 4 5 -1 4 4 -1...
result:
ok puzzle solved
Test #4:
score: -100
Wrong Answer
time: 0ms
memory: 3628kb
input:
2 2 1 OO OO OP PP 1 2 PP
output:
11 -1 2 1 -1 2 0 -3 1 0 -3 0 0 -2 2 2 -4 2 2 -1 2 1 -4 2 1 1 1 1 -4 2 2 -4 2 1
result:
wrong answer Integer parameter [name=y_1] equals to 0, violates the range [1, 2]