QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#519446#5416. Fabulous Fungus FrenzyA6n6d6y6WA 0ms3636kbC++141.9kb2024-08-14 20:16:362024-08-14 20:16:36

Judging History

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

  • [2024-08-14 20:16:36]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3636kb
  • [2024-08-14 20:16:36]
  • 提交

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;
bool check(int k){
	cnt.clear();
	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]]--;
			else if(cnt['*'])cnt['*']--;
			else return 0;
		}
	}
	return 1;
}
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;l<=n;l++){
				if(x||y)break;
				for(int r=1;r<=m;r++)
					if(!vis[l][r]&&b[l][r]==c[k][i][j]){x=l,y=r;break;}
			}
			for(int l=1;l<=n;l++){
				if(x||y)break;
				for(int r=1;r<=m;r++)
					if(!vis[l][r]&&b[l][r]=='*'){x=l,y=r;break;}
			}
			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)){
		bool flag=1;
		for(int i=1;i<=k;i++)
			if(check(i))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: 3636kb

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: 3516kb

input:

2 2 1
OO
OO

PP
PP

1 2
OP

output:

-1

result:

ok puzzle solved

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3580kb

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:

196
4 1 1
-3 1 5
-2 1 6
-3 1 4
-2 1 5
-2 1 6
-3 1 3
-2 1 4
-2 1 5
-2 1 6
-3 1 2
-2 1 3
-2 1 4
-2 1 5
-2 1 6
-3 1 1
-2 1 2
-2 1 3
-2 1 4
-2 1 5
-2 1 6
3 1 1
2 1 1
1 1 1
-4 3 3
-4 4 3
-2 4 4
-2 4 5
-2 4 6
-2 4 7
-2 4 8
-3 1 2
-2 1 3
-2 1 4
-3 1 1
-2 1 2
-2 1 3
-2 1 4
4 1 1
-3 1 5
-2 1 6
-3 1 4
-2 1 5
...

result:

wrong answer puzzle remain unsolved