QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#471491 | #5416. Fabulous Fungus Frenzy | Mr_Vatican | WA | 0ms | 3732kb | C++14 | 3.7kb | 2024-07-10 21:35:33 | 2024-07-10 21:35:37 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define N 25
#define V 62
#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();
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;
while(1)
{
int tmp=Choose(lst);
if(!tmp) break;
if(tmp==1) Stamp1(lst);
else Stamp2(lst);
}
return 0;
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: 0
Wrong Answer
time: 0ms
memory: 3732kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
result:
wrong output format Unexpected end of file - int32 expected