QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#519500#5416. Fabulous Fungus FrenzyA6n6d6y6WA 1ms3724kbC++141.8kb2024-08-14 20:33:292024-08-14 20:33:29

Judging History

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

  • [2024-08-14 20:33:29]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3724kb
  • [2024-08-14 20:33:29]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
char ch[21],c[21][21][21],b[21][21],(&a)[21][21]=c[0];
struct opt{int op,x,y;}g;
vector<opt>ans;map<char,int>cnt;
int h[21],w[21],vis[21][21],&n=h[0],&m=w[0],k;
int check(int k){
	cnt.clear();int res=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cnt[b[i][j]]++;
	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['*'])cnt['*']--;
			else return -1;
		}
	}
	return res;
}
void solve(int k){
	memset(vis,0,sizeof vis);
	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;!x&&l<=n;l++){
				for(int r=1;r<=m;r++)
					if(!vis[l][r]&&b[l][r]==c[k][i][j]){x=l,y=r;}
			}
			for(int l=1;!x&&l<=n;l++){
				for(int r=1;r<=m;r++)
					if(!vis[l][r]&&b[l][r]=='*'){x=l,y=r;}
			}
			if(!x||!y){cerr<<"WARNING:BUG on solving "<<k<<"!!!\n";}
			while(y<j)swap(b[x][y],b[x][y+1]),ans.push_back({-1,x,y++});
			while(y>j)swap(b[x][y],b[x][y-1]),ans.push_back({-2,x,y--});
			while(x<i)swap(b[x][y],b[x+1][y]),ans.push_back({-3,x++,y});
			while(x>i)swap(b[x][y],b[x-1][y]),ans.push_back({-4,x--,y});
			vis[i][j]=1;
		}
	}
	for(int i=1;i<=h[k];i++)
		for(int j=1;j<=w[k];j++)
			b[i][j]='*';
	if(k)ans.push_back({k,1,1});
}
int main(){
	cin>>n>>m>>k;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>a[i][j];
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			cin>>b[i][j];
	for(int i=1;i<=k;i++){
		cin>>h[i]>>w[i];
		for(int j=1;j<=h[i];j++)
			for(int l=1;l<=w[i];l++)
				cin>>c[i][j][l];
	}
	while(check(0)==-1){
		bool flag=1;
		for(int i=1;i<=k;i++)
			if(check(i)>0)flag=0,solve(i);
		if(flag){cout<<"-1\n";return 0;}
	}
	solve(0);reverse(ans.begin(),ans.end());
	cout<<ans.size()<<'\n';
	for(auto [op,x,y]:ans)
		cout<<op<<' '<<x<<' '<<y<<'\n';
	return 0;
}

详细

Test #1:

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

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:

20
-2 3 3
-2 3 2
-4 3 3
-1 3 2
-2 2 3
-2 2 2
-4 2 3
-1 2 2
-2 1 3
-2 1 2
-2 1 3
1 1 1
-2 3 2
-2 3 3
-2 2 2
-2 2 3
-4 2 1
-4 3 1
-2 3 2
-2 3 3

result:

ok puzzle solved

Test #2:

score: 0
Accepted
time: 0ms
memory: 3676kb

input:

2 2 1
OO
OO

PP
PP

1 2
OP

output:

-1

result:

ok puzzle solved

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 3724kb

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:

350
-2 4 8
-2 4 7
-2 4 8
-2 4 6
-2 4 7
-2 4 8
-2 4 5
-2 4 6
-2 4 7
-2 4 8
-2 4 4
-2 4 5
-2 4 6
-2 4 7
-2 4 8
-2 4 3
-2 4 4
-2 4 5
-2 4 6
-2 4 7
-2 4 8
-2 4 2
-2 4 3
-2 4 4
-2 4 5
-2 4 6
-2 4 7
-2 4 8
-2 3 8
-2 3 7
-2 3 8
-2 3 6
-2 3 7
-2 3 8
-2 3 5
-2 3 6
-2 3 7
-2 3 8
-2 3 4
-2 3 5
-2 3 6
-2 3 7
-2...

result:

wrong answer puzzle remain unsolved