QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#520747#5416. Fabulous Fungus FrenzyzWA 1ms3980kbC++142.4kb2024-08-15 15:18:032024-08-15 15:18:04

Judging History

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

  • [2024-08-15 15:18:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3980kb
  • [2024-08-15 15:18:03]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int N=22,M=100;
char S[N];
int step;
int n,m,k;
int s[N][N][N];
int a[N][N];
int h[N],w[N];
int col[M];
struct Opt{
    int op,x,y;
}O[400005];
int trans(char c){
	if(c>96) return c-86;
	if(c>64) return c-28;
	return c-47;
}
bool check2(int x){
    for(int i=1;i<=h[x];i++) for(int j=1;j<=w[x];j++)
        if(a[i][j]!=s[x][i][j]) return 0;
    return 1;
}
bool check(int x){
    //if(check2(x)) return 0;
    for(int i=0;i<=62;i++) col[i]=0;
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) col[a[i][j]]++;
	for(int i=1;i<=h[x];i++)
		for(int j=1;j<=w[x];j++){
			if(col[s[x][i][j]]) --col[s[x][i][j]];
			else if(col[0]) --col[0];
			else return 0;
		}
	return 1;
}
char tr(int x){
    if(x<11) return x+47;
    if(x<37) return x+86;
    return x+28;
}
void solve(int now){
    for(int i=1;i<=h[now];i++){
        for(int j=1;j<=w[now];j++){
            if(a[i][j]==s[now][i][j]) continue;
            int x=0,y=0;
            for(int p=1;!x&&p<=n;p++) for(int q=1;!x&&q<=m;q++)
                if((p>i||p<i&&q>w[x]||p==i&&q>=j)&&a[p][q]==s[now][i][j]) x=p,y=q;
            for(int p=1;!x&&p<=n;p++) for(int q=1;!x&&q<=m;q++)
                if((p>i||p<i&&q>w[x]||p==i&&q>=j)&&a[p][q]==0) x=p,y=q;
            //下左右上 
            while(x<i) swap(a[x][y],a[x+1][y]),O[++step]={-3,x,y},++x;
            while(y>j) swap(a[x][y],a[x][y-1]),O[++step]={-2,x,y},--y;
            while(y<j) swap(a[x][y],a[x][y+1]),O[++step]={-1,x,y},++y;
            while(x>i) swap(a[x][y],a[x-1][y]),O[++step]={-4,x,y},--x;
            a[i][j]=0;
        }
    }
    O[++step]={now,1,1};
}
int main(){
	scanf("%d%d%d",&n,&m,&k);
	h[0]=n,w[0]=m;
	for(int i=1;i<=n;i++){
		scanf("%s",S+1);
		for(int j=1;j<=m;j++)
			s[0][i][j]=trans(S[j]);
	}
	for(int i=1;i<=n;i++){
		scanf("%s",S+1);
		for(int j=1;j<=m;j++)
			a[i][j]=trans(S[j]);
	}
	for(int l=1;l<=k;l++){
		scanf("%d%d",&h[l],&w[l]);
		for(int i=1;i<=h[l];i++){
			scanf("%s",S+1);
			for(int j=1;j<=w[l];j++)
				s[l][i][j]=trans(S[j]);
		}
	}
	while(1){
		bool f=1;
		if(check(0)) break;
		for(int i=1;i<=k;i++){
			if(check(i)){
				solve(i);
				f=0;
			}
		}
		if(f){
			puts("-1");
			return 0;
		}
	}
	solve(0);
	printf("%d\n",step-1);
	for(int i=step-1;i;i--) printf("%d %d %d\n",O[i].op,O[i].x,O[i].y);
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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

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

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:

168
4 1 1
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
4 1 1
3 1 1
-4 2 1
-4 3 1
-4 4 1
-2 4 2
-2 4 3
-2 4 4
-2 4 5
-2 4 6
2 1 1
1 1 1
-4 3 3
-4 4 3
-2 4 4
-2 4 5
4 1 1
3 1 1
-4 2 1
-4 3 1
-4 4 1
-2 4 2
-2 4 3
-2 4 4
2 1 1
-4 4 8
-1 4 7
-1 4 6
-1 4 5
-1 4 4
-1 4 3
-1 4 2
-1 4 1...

result:

wrong answer Integer parameter [name=y_130] equals to 0, violates the range [1, 8]