QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#473911 | #5416. Fabulous Fungus Frenzy | jiaziqi | WA | 2ms | 4204kb | C++14 | 3.4kb | 2024-07-12 14:58:18 | 2024-07-12 14:58:19 |
Judging History
answer
#include<bits/stdc++.h>
#define ShuaiBi main
#define Genshin 1+1
#define is ==
#define a_shit 2
using namespace std;
typedef long long ll;
const int N=70;
map<char,int> mp1;
map<int,char> mp2;
void init(){
srand(time(0));
for(int i=0;i<26;i++) mp1[char('a'+i)]=i,mp2[i]=char('a'+i);
for(int i=26;i<52;i++) mp1[char('A'+i-26)]=i,mp2[i]=char('A'+i-26);
for(int i=52;i<62;i++) mp1[char('0'+i-52)]=i,mp2[i]=char('0'+i-52);
mp1['*']=63,mp2[63]='*';
}
int t[N],need[N][N],n,m,k,gen;
struct ass{
int a[N][N],n,m;
void read(){
char s[N];
for(int i=1;i<=n;i++){
scanf("%s",s+1);
for(int j=1;j<=m;j++)
a[i][j]=mp1[s[j]];
}
}
void write(){
for(int i=1;i<=n;i++,putchar('\n'))
for(int j=1;j<=m;j++)
cout<<mp2[a[i][j]];
cout<<endl;
}
}T,M[N];
struct point{int x,y;};
struct node{int id,x,y;};
vector<node> ans;
int dx[]={0,0,0,1,-1},dy[]={0,1,-1,0,0};
void Swap(int x,int y,int id){
ans.push_back(node{-id,x,y});
swap(T.a[x][y],T.a[x+dx[id]][y+dy[id]]);
}
void Move(point a,point b){
if(!a.x && !a.y) return;
if(a.x<b.x){
while(a.x<b.x) Swap(a.x,a.y,3),a.x++;
while(a.x>b.x) Swap(a.x,a.y,4),a.x--;
while(a.y<b.y) Swap(a.x,a.y,1),a.y++;
while(a.y>b.y) Swap(a.x,a.y,2),a.y--;
}else{
while(a.y<b.y) Swap(a.x,a.y,1),a.y++;
while(a.y>b.y) Swap(a.x,a.y,2),a.y--;
while(a.x>b.x) Swap(a.x,a.y,4),a.x--;
while(a.x<b.x) Swap(a.x,a.y,3),a.x++;
}
}
point Find(int id,point x,int c){
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
if((i>x.x || (i==x.x&& j>x.y) || (i<x.x && j>M[id].m)) && T.a[i][j]==c) return point{i,j};
return point{0,0};
}
void count(){
memset(t,0,sizeof(t));
for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) t[T.a[i][j]]++;
gen=t[63];
}
bool check(int id){
int cnt=0;
for(int i=0;i<62;i++) cnt+=max(0,need[id][i]-t[i]);
if(cnt>gen) return 0;
for(int i=0;i<62;i++)
if(need[id][i] && t[i]) return 1;
return 0;
}
#define shit Find(id,point{i,j},M[id].a[i][j])
void Cover(int id){
for(int i=1;i<=M[id].n;i++)
for(int j=1;j<=M[id].m;j++)
if(T.a[i][j]!=M[id].a[i][j])
// printf("(%d %d)->(%d %d)\n",shit.x,shit.y,i,j),
Move(Find(id,point{i,j},M[id].a[i][j]),point{i,j});
// T.write();cout<<"!"<<endl;
for(int i=1;i<=M[id].n;i++)
for(int j=1;j<=M[id].m;j++)
if(T.a[i][j]!=M[id].a[i][j] && T.a[i][j]!=63)
//printf("(%d,%d)要填* M:%c\n",i,j,mp2[T.a[i][j]]),
Move(Find(id,point{i,j},63),point{i,j});
//T.write();cout<<"?"<<endl;
for(int i=1;i<=M[id].n;i++)
for(int j=1;j<=M[id].m;j++)
T.a[i][j]=63;
ans.push_back(node{id,1,1});
}
int ShuaiBi(){
//freopen("write.out","w",stdout);
init();
scanf("%d%d%d",&n,&m,&k);
M[k+1].n=T.n=n,M[k+1].m=T.m=m;
M[k+1].read(),T.read();
for(int i=1;i<=k;i++){
scanf("%d%d",&M[i].n,&M[i].m);
M[i].read();
}
for(int i=1;i<=k+1;i++)
for(int j=1;j<=M[i].n;j++) for(int k=1;k<=M[i].m;k++)
need[i][M[i].a[j][k]]++;
int i=1,cou;
while(Genshin is a_shit){
count(),cou=0;
while(cou<k && !check(i)) i=i%k+1,cou++;
if(cou==k) break;
//printf("id:%d\n",i);T.write();
Cover(i);
}
int cnt=0;
for(int i=0;i<62;i++) cnt+=max(0,need[k+1][i]-t[i]);
if(cnt>gen) return puts("-1"),0;
for(int i=0;i<62;i++)
if(need[k+1][i] && t[i]){Cover(k+1),ans.pop_back();break;}
printf("%d\n",(int)ans.size());
while(!ans.empty()) printf("%d %d %d\n",ans.back().id,ans.back().x,ans.back().y),ans.pop_back();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3964kb
input:
3 3 1 OOO GOG BGB OOO GGG BBB 3 1 B G B
output:
19 -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 -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: 3916kb
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: 3984kb
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:
205 2 1 1 -4 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 -4 4 1 -2 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -4 3 2 -2 3 3 -2 3 4 -2 3 5 -2 3 6 -2 3 7 -2 3 8 1 1 1 -4 2 1 -4 3 1 -4 4 1 -2 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 -2 4 8 1 1 1 -4 2 1 -4 3 1 -4 4 1 -2 4 2 -2 4 3 -2 4 4 -2 4 5 -2 4 6 -2 4 7 1 1 1 -4 3 2...
result:
ok puzzle solved
Test #4:
score: 0
Accepted
time: 0ms
memory: 3888kb
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: 3972kb
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: 3784kb
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: 3972kb
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: 4204kb
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: 3940kb
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: 2ms
memory: 4108kb
input:
20 20 2 pqo3Mcpvo74RFSsJszsa znrYm92Qr8fbqhbCTOgq 4KiMYr0kLAxPGNG15x7L QHKmq6xaJ4PU4msuRAiv UBfS6VUO87hRnMAjGXKX zCgknw3FfhdifmVcT6FF GH6ohIAzZuprlC3vMDVh mHIJ9KlQvWxt6EgGbJkA 3SwJNhRSdEeF9BNtc9k2 mZmEuriH7Rc4ccMjqI0Y cFfI8TC1iM4PkKziLOiN 15CUjuwudnrums3c3dsl ekL52LiFEpzmU4vaGtuX CfrnQtWb5zAN9oQS2fj...
output:
6970 2 1 1 -2 16 5 -2 16 6 -2 16 7 -2 16 8 -2 16 9 -2 16 10 -2 16 11 -2 16 12 -2 16 13 -2 16 14 -2 16 15 -2 16 16 -2 16 17 -2 16 18 -2 16 19 -2 16 20 -3 15 20 -3 14 20 -3 13 20 -3 12 20 -3 11 20 -3 10 20 -3 9 20 -3 8 20 -3 7 20 -3 6 20 -3 5 20 -3 4 20 -3 3 20 2 1 1 -2 16 5 -2 16 6 -2 16 7 -2 16 8 -2...
result:
wrong answer puzzle remain unsolved