QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#471848#5416. Fabulous Fungus FrenzypeterWA 0ms3784kbC++143.9kb2024-07-11 10:07:102024-07-11 10:07:10

Judging History

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

  • [2024-07-11 10:07:10]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3784kb
  • [2024-07-11 10:07:10]
  • 提交

answer

// Problem: F - Fabulous Fungus Frenzy
// Contest: Virtual Judge - 2024-07-10 贪心与构造
// URL: https://vjudge.net/contest/639440#problem/F
// Memory Limit: 507 MB
// Time Limit: 1000 ms

#include <bits/stdc++.h>

using namespace std;

const int maxn=25;
const int maxm=155;
int num[maxm],tn[maxn],ttm[maxn],tnum[maxn][maxm],n,m,k;
char mp[maxn][maxn],ch[maxn][maxn][maxn];
struct step{
	int op,x,y;
	step(){}
	step(int opp,int xx,int yy){
		op=opp;
		x=xx;
		y=yy;
	}
};
vector<step> vec;
bool vis[maxn];

void move(int sx,int sy,int tx,int ty){
	if(sy<ty){
		while(sy<ty){
			swap(mp[sx][sy],mp[sx][sy+1]);
			vec.push_back(step(-2,sx,sy+1));
			sy++;
		}
		while(sx<tx){
			swap(mp[sx][sy],mp[sx+1][sy]);
			vec.push_back(step(-4,sx+1,sy));
			sx++;
		}
		while(sx>tx){
			swap(mp[sx][sy],mp[sx-1][sy]);
			vec.push_back(step(-3,sx-1,sy));
			sx--;
		}
	}else{
		while(sx<tx){
			swap(mp[sx][sy],mp[sx+1][sy]);
			vec.push_back(step(-4,sx+1,sy));
			sx++;
		}
		while(sx>tx){
			swap(mp[sx][sy],mp[sx-1][sy]);
			vec.push_back(step(-3,sx-1,sy));
			sx--;
		}
		while(sy>ty){
			swap(mp[sx][sy],mp[sx][sy-1]);
			vec.push_back(step(-1,sx,sy-1));
			sy--;
		}
	}
}
int check(int x){
	int tt=0;
	for(int i='0';i<='z';i++) tt+=max(0,tnum[x][i]-num[i]);
	return tt;
}
void pp(int now){
	for(int i=1;i<=tn[now];i++){
		for(int j=1;j<=ttm[now];j++){
			int tx=-1,ty,px=-1,py;
			for(int p=1;p<=n;p++){
				for(int q=1;q<=m;q++){
					if(p<i&&q<=ttm[now]) continue;
					if(p==i&&q<j) continue;
					if(mp[p][q]==ch[now][i][j]){
						tx=p;
						ty=q;
						break;
					}else if(px==-1&&mp[p][q]=='#'){
						px=p;
						py=q;
					}
				}
				if(tx!=-1) break;
			}
			if(tx!=-1) move(tx,ty,i,j);
			else move(px,py,i,j);
			if(mp[i][j]=='#') num[0]--;
			else num[mp[i][j]]--;
			num[0]++;
			mp[i][j]='#';
		}
	}
}

queue<int> que;

int main(){
	
	scanf("%d %d %d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%s",ch[k+1][i]+1);
		for(int j=1;j<=m;j++) tnum[k+1][ch[k+1][i][j]]++;
	}
	tn[k+1]=n;
	ttm[k+1]=m;
	for(int i=1;i<=n;i++){
		scanf("%s",mp[i]+1);
		for(int j=1;j<=m;j++) num[mp[i][j]]++;
	}
	// for(int i='0';i<='z';i++){
		// printf("%c : %d\n",i,num[i]);
	// }
	for(int i=1;i<=k;i++){
		scanf("%d %d",&tn[i],&ttm[i]);
		for(int j=1;j<=tn[i];j++){
			scanf("%s",ch[i][j]+1);
			for(int p=1;p<=ttm[i];p++) tnum[i][ch[i][j][p]]++;
		}
		if(check(i)<=num[0]){
			// puts("here");
			vis[i]=1;
			que.push(i);
		}
	}
	
	while(!que.empty()){
		int now=que.front();
		que.pop();
		pp(now);
		// for(int i=1;i<=n;i++){
			// for(int j=1;j<=m;j++) putchar(mp[i][j]);
			// puts("");
		// }
		vec.push_back(step(0,1,1));
		while(1){
			int pt=0;
			for(int i='0';i<='z';i++){
				if(tnum[now][i]&&num[i]){
					pt=i;
					break;
				}
			}
			if(!pt) break;
			int tx=-1,ty;
			for(int i=1;i<=tn[now];i++){
				for(int j=1;j<=ttm[now];j++){
					if(ch[now][i][j]==pt){
						tx=i;
						ty=j;
						break;
					}
				}
				if(tx!=-1) break;
			}
			for(int i=1;i<=n;i++){
				for(int j=1;j<=m;j++){
					if(mp[i][j]==pt){
						// printf("kk%d %d -> %d %d\n",i,j,tx,ty);
						move(i,j,tx,ty);
						num[pt]--;
						num[0]++;
						mp[tx][ty]='#';
						pt=0;
						break;
					}
				}
				if(!pt) break;
			}
			vec.push_back(step(0,1,1));
		}
		// for(int i=1;i<=n;i++){
			// for(int j=1;j<=m;j++) putchar(mp[i][j]);
			// puts("");
		// }
		// printf("pp%d\n",num[0]);
		for(int i=1;i<=k;i++){
			if(vis[i]) continue;
			int tmp=check(i);
			if(tmp<=num[0]&&tmp<tn[i]*ttm[i]){
				vis[i]=1;
				que.push(i);
			}
		}
	}
	
	// printf("kk%d\n",check(k+1));
	
	if(check(k+1)>num[0]) puts("-1");
	else{
		pp(k+1);
		printf("%d\n",(int)vec.size());
		for(int i=(int)vec.size()-1;i>=0;i--) printf("%d %d %d\n",vec[i].op,vec[i].x,vec[i].y);
	}
	
	return 0;
}

详细

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3784kb

input:

3 3 1
OOO
GOG
BGB

OOO
GGG
BBB

3 1
B
G
B

output:

23
-3 1 3
-3 2 3
-3 1 2
-3 2 2
-1 1 1
-1 1 2
0 1 1
-1 2 1
-1 2 2
-3 2 3
0 1 1
-1 2 1
-3 2 2
0 1 1
-1 1 1
-1 1 2
-3 1 3
-3 2 3
0 1 1
-1 3 1
-1 2 1
-3 1 1
-3 2 1

result:

wrong answer puzzle remain unsolved