QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#520135#5416. Fabulous Fungus FrenzydczissbTL 0ms3628kbC++142.4kb2024-08-15 11:02:072024-08-15 11:02:07

Judging History

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

  • [2024-08-15 11:02:07]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:3628kb
  • [2024-08-15 11:02:07]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
int n,k,m,x[21],y[21],vis[21][21];
struct dcz{
	int x,y,z;
};
vector<dcz> ans;
int ton[129];
const int mod=1e9+7;
char mp[21][21],ed[21][21],z[21][21][21];
int check(int g){
//	cout<<g<<endl;
	memset(ton,0,sizeof ton);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			ton[(int)mp[i][j]]++;
		}
	}
	int ans=0;
	for(int i=1;i<=x[g];i++){
		for(int j=1;j<=y[g];j++){
//			cout<<(int)z[g][i][j]<<" ";
			if(ton[(int)z[g][i][j]]) ton[(int)z[g][i][j]]--,ans++; 
			else if(ton['&']) ton['&']--;
			else return -1;
		}
//		cout<<endl;
	}
	return ans;
}

void solve(int g){
	memset(vis,0,sizeof vis);
	for(int i=1;i<=x[g];i++){
		for(int j=1;j<=y[g];j++){
			int p=0,q=0;
			for(int l=1;l<=n;l++){
				for(int r=1;r<=m;r++){
					if(p||q) break;
					if(!vis[l][r]&&mp[l][r]==z[g][i][j]){
						p=l,q=r;
						break;
					}
				}
				if(p||q) break;
			}
			for(int l=1;l<=n;l++){
				for(int r=1;r<=m;r++){
					if(p||q) break;
					if(!vis[l][r]&&mp[l][r]=='&'){
						p=l,q=r;
						break;
					}
				}
				if(p||q) break;
			}
//			cout<<p<<" "<<q<<endl;
			while(p<i) swap(mp[p][q],mp[p+1][q]),ans.push_back({-3,p++,q});
			while(q<j) swap(mp[p][q],mp[p][q+1]),ans.push_back({-1,p,q++});
			while(p>i) swap(mp[p][q],mp[p-1][q]),ans.push_back({-4,p--,q});
			while(q>j) swap(mp[p][q],mp[p][q-1]),ans.push_back({-2,p,q--});
			vis[p][q]=1;
		}
	}
	for(int i=1;i<=x[g];i++){
		for(int j=1;j<=y[g];j++){
			mp[i][j]='&';
		}
	}
	if(g) ans.push_back({g,1,1});
}

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n>>m>>k;
	x[0]=n,y[0]=m;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>z[0][i][j];
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			cin>>mp[i][j];
		}
	}
	for(int o=1;o<=k;o++){
		cin>>x[o]>>y[o];
		for(int i=1;i<=x[o];i++){
			for(int j=1;j<=y[o];j++){
				cin>>z[o][i][j];
			}
		}
	}
//	for(int o=0;o<=k;o++){
//		for(int i=1;i<=x[o];i++){
//			for(int j=1;j<=y[o];j++){
//				cout<<(int)z[o][i][j]<<" ";
//			}
//			cout<<endl;
//		}
//		cout<<endl;
//	}
	while(check(0)<0){
		int f=0;
		for(int i=1;i<=k;i++){
			if(check(i)>0){f=1;solve(f);}
		}
		if(!f) cout<<-1,exit(0);
	}
	solve(0);
	cout<<ans.size()<<endl;
	reverse(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++){
		cout<<ans[i].x<<" "<<ans[i].y<<" "<<ans[i].z<<endl;
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:

13
-2 3 2
-4 3 3
-1 3 2
-2 2 2
-4 2 3
-1 2 2
-2 1 3
-2 1 2
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: 3556kb

input:

2 2 1
OO
OO

PP
PP

1 2
OP

output:

-1

result:

ok puzzle solved

Test #3:

score: -100
Time Limit Exceeded

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:


result: