QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#476960 | #5416. Fabulous Fungus Frenzy | zhao_daodao | WA | 7ms | 4068kb | C++20 | 4.2kb | 2024-07-13 21:58:58 | 2024-07-13 21:58:59 |
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=Pair{i,j};
for(int x=1;x<=n;x++){
for(int y=1;y<=m;y++)
if(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;x++){
for(int y=1;y<=m;y++)
if(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: 3756kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
38 -2 3 3 -2 3 2 -2 3 3 -4 3 3 -2 2 3 -4 3 1 -2 3 2 -2 3 3 -4 2 3 -4 3 3 -2 1 3 -4 2 1 -4 3 1 -2 3 2 -2 3 3 1 1 1 -2 3 2 -2 2 2 -2 2 3 -4 2 1 -4 3 1 -2 3 2 1 1 1 -2 3 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 3 3 -4 3 1 -4 2 1 -4 3 1 -2 3 2 -2 3 3
result:
ok puzzle solved
Test #2:
score: 0
Accepted
time: 0ms
memory: 3548kb
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: 3576kb
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:
645 -2 4 8 -2 4 7 -2 4 8 -2 4 6 -2 4 7 -2 4 8 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -2 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -4 4 8 -4 4 7 -2 4 8 -4 4 6 -2 4 7 -2 4 8 -4 4 5 -2 4 6 -2 4 7 -2 4 8 -4 4 4 -2 4 5 -2 4 6 -2 4 7 -2...
result:
ok puzzle solved
Test #4:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
2 2 1 OO OO OP PP 1 2 PP
output:
12 -2 2 2 -4 2 2 -4 2 1 1 1 1 -4 2 2 -1 2 1 -4 2 1 -2 2 2 1 1 1 -4 2 2 -4 2 1 -2 2 2
result:
ok puzzle solved
Test #5:
score: 0
Accepted
time: 0ms
memory: 3548kb
input:
2 2 1 OO OO OP PO 2 1 P P
output:
8 -2 2 2 -4 2 2 -4 2 1 -2 2 2 1 1 1 -2 2 2 -3 1 2 -4 2 1
result:
ok puzzle solved
Test #6:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
2 2 1 OO OO OP PO 2 2 PP PP
output:
-1
result:
ok puzzle solved
Test #7:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
2 2 1 OO OO OP PP 1 2 OP
output:
13 -2 2 2 -4 2 2 -4 2 1 -2 2 2 1 1 1 -4 2 2 -4 2 1 -2 2 2 1 1 1 -4 2 2 -2 1 2 1 1 1 -4 2 2
result:
ok puzzle solved
Test #8:
score: 0
Accepted
time: 4ms
memory: 3972kb
input:
20 20 20 bofelagiqboebdqplbhq qsrksfthhptcmikjohkt qrnhpoatbekggnkdonet aoalekbmpbisgflbhmol djnhnlitcakltqgegqrt fdctfarsmbnbeosdgilo ttrsljgiratfmioajorh gorljkihdnmnofnblfhm bqjkaehetdjlgctmijpc geslcskpoqjcgtbdspoa riqthroqmmhqgprqhsba fdiarrcomockfqdjjdkd jsbnigfqgsfekbbnnkir ildqctqtqrpcetaocp...
output:
17722 -2 20 20 -2 20 19 -2 20 20 -2 20 18 -2 20 19 -2 20 20 -2 20 17 -2 20 18 -2 20 19 -2 20 20 -2 20 16 -2 20 17 -2 20 18 -2 20 19 -2 20 20 -2 20 15 -2 20 16 -2 20 17 -2 20 18 -2 20 19 -2 20 20 -2 20 14 -2 20 15 -2 20 16 -2 20 17 -2 20 18 -2 20 19 -2 20 20 -2 20 13 -2 20 14 -2 20 15 -2 20 16 -2 20 ...
result:
ok puzzle solved
Test #9:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
20 20 2 HbevPluVL5ORtUFcV9gf Mrq6zdTPMPnwlN7Fpzx6 Nfp71dVuxTZp9Qet0Ca9 ugbaF34DquDdbUnk5x7V fDFszn4PmvMpJ5BDWueJ 2YvFxKJgst8XbftPfy9T F7Q4huk87Lrp1M7i08is Q41E5AqLkkP3Q5qONXC2 MuM7iIzev3ZpxItvriQK 6OBdEC0sso5vdNQlrCSR BJQtKjN6RmppsMGIYL81 yyKsWJSoKorGGblNle0r RkKEQACh8f0bS5nPTtJH fQgoc39vdsPAUmxlYYL...
output:
-1
result:
ok puzzle solved
Test #10:
score: -100
Wrong Answer
time: 7ms
memory: 4068kb
input:
20 20 2 pqo3Mcpvo74RFSsJszsa znrYm92Qr8fbqhbCTOgq 4KiMYr0kLAxPGNG15x7L QHKmq6xaJ4PU4msuRAiv UBfS6VUO87hRnMAjGXKX zCgknw3FfhdifmVcT6FF GH6ohIAzZuprlC3vMDVh mHIJ9KlQvWxt6EgGbJkA 3SwJNhRSdEeF9BNtc9k2 mZmEuriH7Rc4ccMjqI0Y cFfI8TC1iM4PkKziLOiN 15CUjuwudnrums3c3dsl ekL52LiFEpzmU4vaGtuX CfrnQtWb5zAN9oQS2fj...
output:
41769 -2 20 20 -2 20 19 -2 20 20 -2 20 18 -2 20 19 -2 20 20 -2 20 17 -2 20 18 -2 20 19 -2 20 20 -2 20 16 -2 20 17 -2 20 18 -2 20 19 -2 20 20 -2 20 15 -2 20 16 -2 20 17 -2 20 18 -2 20 19 -2 20 20 -2 20 14 -2 20 15 -2 20 16 -2 20 17 -2 20 18 -2 20 19 -2 20 20 -2 20 13 -2 20 14 -2 20 15 -2 20 16 -2 20 ...
result:
wrong answer puzzle remain unsolved