QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#520880 | #5416. Fabulous Fungus Frenzy | q | Compile Error | / | / | C++23 | 4.7kb | 2024-08-15 17:06:40 | 2024-08-15 17:06:41 |
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,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++) 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]=1;
}
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;
}
#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,0,sizeof vis);
for(int i=1;i<=h[k];i++) for(int j=1;j<=h[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]=1;
}
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;
}
详细
answer.code:59:11: error: redefinition of ‘const int N’ 59 | const int N=25; | ^ answer.code:2:11: note: ‘const int N’ previously defined here 2 | const int N=25; | ^ answer.code:60:5: error: redefinition of ‘int n’ 60 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:3:5: note: ‘int n’ previously declared here 3 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:60:7: error: redefinition of ‘int m’ 60 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:3:7: note: ‘int m’ previously declared here 3 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:60:9: error: redefinition of ‘int k’ 60 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:3:9: note: ‘int k’ previously declared here 3 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:60:11: error: redefinition of ‘int mp [305]’ 60 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^~ answer.code:3:11: note: ‘int mp [305]’ previously declared here 3 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^~ answer.code:60:19: error: redefinition of ‘int c [25][25][25]’ 60 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:3:19: note: ‘int c [25][25][25]’ previously declared here 3 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:60:30: error: redefinition of ‘int h [25]’ 60 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:3:30: note: ‘int h [25]’ previously declared here 3 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:60:35: error: redefinition of ‘int w [25]’ 60 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:3:35: note: ‘int w [25]’ previously declared here 3 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:60:40: error: redefinition of ‘int a [25][25]’ 60 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:3:40: note: ‘int a [25][25]’ previously declared here 3 | int n,m,k,mp[305],c[N][N][N],h[N],w[N],a[N][N]; | ^ answer.code:61:39: error: redefinition of ‘std::vector<std::tuple<int, int, int> > ans’ 61 | std::vector<std::tuple<int,int,int> > ans; | ^~~ answer.code:4:39: note: ‘std::vector<std::tuple<int, int, int> > ans’ previously defined here 4 | std::vector<std::tuple<int,int,int> > ans; | ^~~ answer.code:62:13: error: redefinition of ‘void get_mp()’ 62 | inline void get_mp(){ | ^~~~~~ answer.code:5:13: note: ‘void get_mp()’ previously defined here 5 | inline void get_mp(){ | ^~~~~~ answer.code:68:12: error: redefinition of ‘int chk(int)’ 68 | inline int chk(int k){ | ^~~ answer.code:11:12: note: ‘int chk(int)’ previously defined here 11 | inline int chk(int k){ | ^~~ answer.code:79:13: error: redefinition of ‘void work(int)’ 79 | inline void work(int k){ | ^~~~ answer.code:22:13: note: ‘void work(int)’ previously defined here 22 | inline void work(int k){ | ^~~~ answer.code:94:5: error: redefinition of ‘int main()’ 94 | int main(){ | ^~~~ answer.code:37:5: note: ‘int main()’ previously defined here 37 | int main(){ | ^~~~