QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#471343#5416. Fabulous Fungus FrenzyzyxawaTL 0ms3828kbC++232.1kb2024-07-10 20:39:422024-07-10 20:39:43

Judging History

你现在查看的是最新测评结果

  • [2024-07-10 20:39:43]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3828kb
  • [2024-07-10 20:39:42]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define trans(c) (isdigit(c)?c-48:(islower(c)?c-87:c-29))
char ch[21];
vector <tuple<int,int,int>> ans;
int n,m,k,a[21][21],c[21][21][21],h[21],w[21],cnt[63],v[21][21];
int check(int k){
	memset(cnt,0,sizeof(cnt));
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) cnt[a[i][j]]++;
	int res=0;
	for(int i=1;i<=h[k];i++){
		for(int j=1;j<=w[k];j++){
			if(cnt[c[k][i][j]]) cnt[c[k][i][j]]--,res++;
			else if(cnt[0]) cnt[0]--;
			else return -1;
		}
	}
	return res;
}
void solve(int k){
	memset(v,0,sizeof(v));
	for(int i=1;i<=h[k];i++){
		for(int j=1;j<=w[k];j++){
			int x=0,y=0;
			for(int l=1;l<=n;l++) for(int r=1;r<=m;r++) if(!v[l][r]&&a[l][r]==c[k][i][j]) x=l,y=r;
			if(!x) for(int l=1;l<=n;l++) for(int r=1;r<=m;r++) if(!v[l][r]&&!a[l][r]) x=l,y=r;
			while(x<i) swap(a[x][y],a[x+1][y]),ans.push_back({-3,x++,y});
			while(y<j) swap(a[x][y],a[x][y+1]),ans.push_back({-1,x,y++});
			while(y>j) swap(a[x][y],a[x][y-1]),ans.push_back({-2,x,y--});
			while(x>i) swap(a[x][y],a[x-1][y]),ans.push_back({-4,x--,y});
			v[i][j]=1;
		}
	}
	for(int i=1;i<=h[k];i++) for(int j=1;j<=w[k];j++) a[i][j]=0;
	if(k) ans.push_back({k,1,1});
}
int W(){
	int s=0;
	for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)s+=!a[i][j];
	return s;
}
int main(){
	scanf("%d%d%d",&n,&m,&k),h[0]=n,w[0]=m;
	for(int i=1;i<=n;i++){
		scanf("%s",ch+1);
		for(int j=1;j<=m;j++) c[0][i][j]=trans(ch[j]);
	}
	for(int i=1;i<=n;i++){
		scanf("%s",ch+1);
		for(int j=1;j<=m;j++) a[i][j]=trans(ch[j]);
	}
	for(int i=1;i<=k;i++){
		scanf("%d%d",&h[i],&w[i]);
		for(int j=1;j<=h[i];j++){
			scanf("%s",ch+1);
			for(int l=1;l<=w[i];l++) c[i][j][l]=trans(ch[l]);
		}
	}
	
	int lst=W();
	while(1){
		if(check(0)>=0) break;
		int f=0;
		for(int i=1;i<=k;i++) if(check(i)>0) f=1,solve(i);
		
		int op=W();
		if(op==lst){
			while(1){
				cout<<"Sb\n";
			}
		}
		lst=op;
		
		if(!f) return printf("-1"),0;
	}
	solve(0);
	reverse(begin(ans),end(ans));
	printf("%d\n",ans.size());
	for(auto [a,b,c]:ans) printf("%d %d %d\n",a,b,c);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3828kb

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:

18
-2 3 3
-2 3 2
-2 3 3
-4 3 2
-2 2 2
-2 2 3
-2 1 3
-4 2 1
-4 3 1
-2 3 2
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: -100
Time Limit Exceeded

input:

2 2 1
OO
OO

PP
PP

1 2
OP

output:

Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
Sb
...

result: