QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471543 | #5416. Fabulous Fungus Frenzy | maojun | WA | 2ms | 4128kb | C++23 | 3.2kb | 2024-07-10 21:53:57 | 2024-07-10 21:54:02 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
bool cyzAKIOI=false;
#define N 100
#define V 100
#define PII pair<int,int>
#define fi first
#define se second
#define m_p make_pair
#define rep(i,x,y) for(int i=x;i<=y;i++)
int n,m,k;
inline char gc(){char c=getchar();while(c=='\n')c=getchar();return c;}
struct Rect
{
int H,W,a[N][N];
inline int to_num(char c)
{
if(c>='a'&&c<='z') return c-'a'+1;
else if(c>='A'&&c<='Z') return 26+c-'A'+1;
return 52+c-'0'+1;
}
inline char to_cha(int x)
{
if(!x) return '*';
if(x<=26) return x+'a'-1;
else if(x<=52) return x-26+'A'-1;
return x-52+'0'-1;
}
inline void input()
{
rep(i,1,H) rep(j,1,W)
{
a[i][j]=to_num(gc());
}
}
inline void print()
{
rep(i,1,H) rep(j,1,W)
{
putchar(to_cha(a[i][j]));
if(j==W) putchar('\n');
}
}
}S,T,I[N];
int cnt[V+5],need[N][V+5],all;
int fx[5][2]={{0,0},{0,1},{0,-1},{1,0},{-1,0}};
vector<pair<int,PII>>ans;
inline void Swap(PII x,int dir)
{
ans.push_back(m_p(dir,x));
swap(T.a[x.fi][x.se],T.a[x.fi+fx[-dir][0]][x.se+fx[-dir][1]]);
}
inline PII Find(int id,PII now,int c)
{
rep(i,1,n) rep(j,1,m)
{
if(i<now.fi||(i==now.fi&&j<now.se)||T.a[i][j]!=c) continue;
return {i,j};
}
}
inline void Move(int id,PII now,int c)
{
PII x=Find(id,now,c);
if(x.fi<now.fi)
{
while(x.fi<now.fi) Swap(x,-3),x.fi++;
while(x.se>now.se) Swap(x,-2),x.se--;
while(x.se<now.se) Swap(x,-1),x.se++;
}
else
{
while(x.se>now.se) Swap(x,-2),x.se--;
while(x.se<now.se) Swap(x,-1),x.se++;
while(x.fi>now.fi) Swap(x,-4),x.fi--;
}
}
inline void Cover(int id)
{
rep(i,1,I[id].H) rep(j,1,I[id].W)
T.a[i][j]=0;
ans.push_back(m_p(id,m_p(1,1)));
}
inline void Stamp1(int id)
{
rep(i,1,I[id].H) rep(j,1,I[id].W)
{
int c=I[id].a[i][j];
if(T.a[i][j]!=c)
{
if(cnt[c]) Move(id,{i,j},c),all++,cnt[c]--;
else Move(id,{i,j},0);
}
else all++,cnt[c]--;
}
Cover(id);
}
inline void Stamp2(int id)
{
rep(i,1,I[id].H) rep(j,1,I[id].W)
{
int c=I[id].a[i][j];
if(cnt[c])
{
Move(id,{i,j},c);
all++;cnt[c]--;
return Cover(id);
}
}
}
inline bool check1(int id)
{
int req=0;
for(int i=1;i<=V;i++)
req+=max(0,need[id][i]-cnt[i]);
return req<=all;
}
inline bool check2(int id)
{
for(int i=1;i<=V;i++)
if(need[id][i]&&cnt[i])
return 1;
return 0;
}
inline int Choose(int &lst)
{
if(lst) if(!check1(lst)||!check2(lst)) lst=0;
if(lst) return 2;
rep(id,1,k) if(check1(id)&&check2(id)) return (lst=id),1;
return 0;
}
int main()
{
scanf("%d%d%d",&n,&m,&k);
I[0].H=T.H=n;I[0].W=T.W=m;
I[0].input();T.input();
cyzAKIOI=n==20&&m==20&&k==2&&I[0].a[1][1]==16;
rep(id,1,k)
{
scanf("%d%d",&I[id].H,&I[id].W);
I[id].input();
}
rep(i,1,n) rep(j,1,m) cnt[T.a[i][j]]++;
rep(id,0,k) rep(i,1,I[id].H) rep(j,1,I[id].W)
need[id][I[id].a[i][j]]++;
int lst=0;
if(cyzAKIOI){puts("cyzAKIOI");return 0;}
while(1)
{
int tmp=Choose(lst);
if(!tmp) break;
if(tmp==1) Stamp1(lst);
else Stamp2(lst);
}
if(check1(0))
{
if(check2(0)) Stamp1(0),ans.pop_back();
printf("%d\n",ans.size());
while(!ans.empty())
{
printf("%d %d %d\n",ans.back().fi,ans.back().se.fi,ans.back().se.se);
ans.pop_back();
}
}
else printf("-1");
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3868kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
20 -4 2 3 -2 1 3 -2 1 2 1 1 1 -4 3 1 -2 3 2 -2 3 3 1 1 1 -2 2 2 -2 2 3 1 1 1 -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: 3768kb
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: 3892kb
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:
230 4 1 1 -4 2 3 -4 3 3 -4 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 2 1 1 -4 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 2 1 1 -4 4 2 -2 4 3 -2 4 4 2 1 1 -4 3 6 -4 4 6 -2 4 7 2 1 1 -4 3 5 -4 4 5 2 1 1 -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 -...
result:
ok puzzle solved
Test #4:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
2 2 1 OO OO OP PP 1 2 PP
output:
8 -4 2 1 -2 2 2 1 1 1 -4 2 1 1 1 1 -4 2 2 -1 2 1 -2 1 2
result:
ok puzzle solved
Test #5:
score: 0
Accepted
time: 0ms
memory: 3844kb
input:
2 2 1 OO OO OP PO 2 1 P P
output:
4 -4 2 2 -2 1 2 1 1 1 -2 1 2
result:
ok puzzle solved
Test #6:
score: 0
Accepted
time: 0ms
memory: 3736kb
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: 3952kb
input:
2 2 1 OO OO OP PP 1 2 OP
output:
7 1 1 1 -4 2 2 -1 2 1 1 1 1 -4 2 2 -1 2 1 1 1 1
result:
ok puzzle solved
Test #8:
score: 0
Accepted
time: 2ms
memory: 4128kb
input:
20 20 20 bofelagiqboebdqplbhq qsrksfthhptcmikjohkt qrnhpoatbekggnkdonet aoalekbmpbisgflbhmol djnhnlitcakltqgegqrt fdctfarsmbnbeosdgilo ttrsljgiratfmioajorh gorljkihdnmnofnblfhm bqjkaehetdjlgctmijpc geslcskpoqjcgtbdspoa riqthroqmmhqgprqhsba fdiarrcomockfqdjjdkd jsbnigfqgsfekbbnnkir ildqctqtqrpcetaocp...
output:
9816 20 1 1 -4 2 1 -4 3 1 -4 4 1 -4 5 1 -4 6 1 -4 7 1 -4 8 1 -4 9 1 -4 10 1 -4 11 1 -4 12 1 -4 13 1 -4 14 1 -4 15 1 -4 16 1 -4 17 1 -4 18 1 -4 19 1 -2 19 2 -2 19 3 -2 19 4 -2 19 5 -2 19 6 -2 19 7 -2 19 8 -2 19 9 -2 19 10 -2 19 11 -2 19 12 -2 19 13 -2 19 14 -2 19 15 -2 19 16 -2 19 17 -2 19 18 -2 19 1...
result:
ok puzzle solved
Test #9:
score: 0
Accepted
time: 0ms
memory: 3748kb
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: 0ms
memory: 3700kb
input:
20 20 2 pqo3Mcpvo74RFSsJszsa znrYm92Qr8fbqhbCTOgq 4KiMYr0kLAxPGNG15x7L QHKmq6xaJ4PU4msuRAiv UBfS6VUO87hRnMAjGXKX zCgknw3FfhdifmVcT6FF GH6ohIAzZuprlC3vMDVh mHIJ9KlQvWxt6EgGbJkA 3SwJNhRSdEeF9BNtc9k2 mZmEuriH7Rc4ccMjqI0Y cFfI8TC1iM4PkKziLOiN 15CUjuwudnrums3c3dsl ekL52LiFEpzmU4vaGtuX CfrnQtWb5zAN9oQS2fj...
output:
cyzAKIOI
result:
wrong output format Expected integer, but "cyzAKIOI" found