QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#476912 | #5416. Fabulous Fungus Frenzy | zhao_daodao | WA | 0ms | 3832kb | C++20 | 4.3kb | 2024-07-13 21:33:53 | 2024-07-13 21:33:53 |
Judging History
answer
#include<bits/stdc++.h>
#define Pair pair<int,int>
using namespace std;
#define F(i,a,b) for(int i=a;i<=(b);i++)
#define dF(i,a,b) for(int i=a;i>=(b);i--)
const string C="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz@";
unordered_map<int,int>mp;
const int MAXN=20+5;
int n,m,k,sum_;
char Now[MAXN][MAXN];
int sx[MAXN],sy[MAXN];char Z[MAXN][MAXN][MAXN];
int tim[70];//@ 通配符
// 当前匹配 Pair{需要,增加多少 @}
inline Pair need(int u){
int now[70];memset(now,0,sizeof now);
F(i,1,sx[u])F(j,1,sy[u])now[mp[Z[u][i][j]]]++;
int ans=0;
F(i,0,C.size()-2)ans+=max(0,now[i]-tim[i]);
return Pair{ans,sx[u]*sy[u]-ans};
}
struct node{int opt;Pair pl;};
vector<node>ans;
//位移
inline void Move(Pair fir,Pair sec){
if(fir.first==sec.first){
if(fir.second+1==sec.second)
ans.push_back(node{-1,fir});
else ans.push_back(node{-2,fir});
}
else{
if(fir.first+1==sec.first)
ans.push_back(node{-3,fir});
else ans.push_back(node{-4,fir});
}
swap(Now[fir.first][fir.second],Now[sec.first][sec.second]);
}
//盖章
inline void change(int u){
F(i,1,sx[u])F(j,1,sy[u]){
bool flag=0;Pair place;
for(int x=1;x<=n&&!flag;x++){
for(int y=1;y<=m&&!flag;y++)
if(x>i||y>j||(x==i&&y==j)){
if(Now[x][y]==Z[u][i][j]){
flag=1,place=Pair{x,y};
}
}
}
if(!flag){
for(int x=1;x<=n&&!flag;x++){
for(int y=1;y<=m&&!flag;y++)
if(x>i||y>j||(x==i&&y==j)){
if(Now[x][y]=='@'){
flag=1;place=Pair{x,y};
}
}
}
}
// cerr<<i<<" "<<j<<" "<<place.first<<" "<<place.second<<"\n";
if(place.first<=i){
while(place.first<i){
Pair ano=Pair{place.first+1,place.second};
Move(place,ano);place=ano;
}
while(place.second<j){
Pair ano=Pair{place.first,place.second+1};
Move(place,ano);place=ano;
}
while(place.second>j){
Pair ano=Pair{place.first,place.second-1};
Move(place,ano);place=ano;
}
}
else{
while(place.second<j){
Pair ano=Pair{place.first,place.second+1};
Move(place,ano);place=ano;
}
while(place.second>j){
Pair ano=Pair{place.first,place.second-1};
Move(place,ano);place=ano;
}
while(place.first>i){
Pair ano=Pair{place.first-1,place.second};
Move(place,ano);place=ano;
}
}
}
F(i,1,sx[u])F(j,1,sy[u])Now[i][j]='@';
memset(tim,0,sizeof tim);
F(i,1,n)F(j,1,m)tim[mp[Now[i][j]]]++;
ans.push_back(node{u,Pair{1,1}});
// F(i,1,n){F(j,1,m)cerr<<Now[i][j];cerr<<"\n";}cerr<<"\n";
}
inline void tiaoshi(){
cout<<n<<" "<<m<<" "<<k<<"\n";
F(i,1,n){F(j,1,m)cout<<Z[k+1][i][j];cout<<"\n";}
F(i,1,n){F(j,1,m)cout<<Now[i][j];cout<<"\n";}
F(_,1,k){
cout<<sx[_]<<" "<<sy[_]<<"\n";
F(i,1,sx[_]){F(j,1,sy[_])cout<<Z[_][i][j];cout<<"\n";}
}
}
signed main(){
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(false);
cin>>n>>m>>k;
sx[k+1]=n,sy[k+1]=m;
F(i,1,n)F(j,1,m)cin>>Z[k+1][i][j];
F(i,1,n)F(j,1,m)cin>>Now[i][j];
F(i,0,C.size()-1)mp[C[i]]=i;
F(_,1,k){
cin>>sx[_]>>sy[_];
F(i,1,sx[_])F(j,1,sy[_])cin>>Z[_][i][j];
}
// tiaoshi();
F(i,1,n)F(j,1,m)tim[mp[Now[i][j]]]++;
while(1){
int maxx=-1,cnt=-1;
F(i,1,k){
Pair now=need(i);
if(now.first<=tim[mp['@']]&&now.second>maxx){
maxx=now.second;cnt=i;
}
}
if(maxx<=0)break;
change(cnt);
}
Pair now=need(k+1);
if(now.first>tim[mp['@']]){
cout<<"-1";
return 0;
}
change(k+1);
ans.pop_back();
cout<<ans.size()<<"\n";
for(int i=(int)ans.size()-1;i>=0;i--){
cout<<ans[i].opt<<" "<<ans[i].pl.first<<" "<<ans[i].pl.second<<"\n";
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3640kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
32 -2 3 3 -3 2 3 -3 1 3 -2 3 2 -2 3 3 -3 2 3 -3 1 3 -2 2 3 -3 1 3 -4 2 3 -2 1 3 -2 1 2 1 1 1 -2 3 2 -3 2 2 -4 3 1 -2 3 2 -2 3 3 1 1 1 -2 3 2 -3 2 2 -2 2 2 -2 2 3 -4 2 1 -4 3 1 -2 3 2 -2 3 3 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: 3832kb
input:
2 2 1 OO OO PP PP 1 2 OP
output:
-1
result:
ok puzzle solved
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3644kb
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:
184 -2 4 8 -3 3 8 -3 2 8 -3 1 8 -2 4 7 -3 3 7 -3 2 7 -3 1 7 -2 4 6 -3 3 6 -3 2 6 -3 1 6 -2 4 5 -3 3 5 -3 2 5 -3 1 5 -2 4 4 -3 3 4 -3 2 4 -3 1 4 -2 4 3 -3 3 3 -3 2 3 -3 1 3 -2 4 2 -3 3 2 -3 2 2 -3 1 2 -2 3 8 -3 2 8 -3 1 8 -2 3 7 -3 2 7 -3 1 7 -2 3 6 -3 2 6 -3 1 6 -2 3 5 -3 2 5 -3 1 5 -2 3 4 -3 2 4 -3...
result:
wrong answer puzzle remain unsolved