QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#514764#7637. Exactly Three NeighborsAlex_wcqWA 124ms6692kbC++141.2kb2024-08-11 10:05:502024-08-11 10:05:51

Judging History

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

  • [2024-08-11 10:05:51]
  • 评测
  • 测评结果:WA
  • 用时:124ms
  • 内存:6692kb
  • [2024-08-11 10:05:50]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m=18,p,q,r[70],v[70][70][70],o[70][70][70],c[70][70],s[20],l[3][10];
void dfs(int h,int t){
	if(h>m||t*q>p*n*m||t*2<n*h) return;
	if(h>=3&&t*q==p*h*n&&o[s[h-1]][s[h]][s[1]]&&o[s[h]][s[1]][s[2]]){
		printf("%d %d\n",h,n);
		for(int i=1;i<=h;++i){ 
			for(int j=0;j<n;++j) putchar(s[i]&(1<<j)?'#':'.');	
			puts("");
		}
		exit(0);
	}
	int *z=(h<=1)?r:v[s[h-1]][s[h]],y=(h<=1)?(1<<n):c[s[h-1]][s[h]];
	random_shuffle(z,z+y);
	for(int i=0;i<y;++i) dfs(h+1,t+__builtin_popcount(s[h+1]=z[i]));
}
int main(){
	scanf("%d%d",&p,&q);
	for(n=1;n<=6;++n){
		for(int i=0;i<(1<<n);++i) r[i]=i;
		for(int i=0;i<(1<<n);++i)
			for(int j=0;j<(1<<n);++j,c[i][j]=0)
				for(int k=0;k<(1<<n);++k){
					for(int t=0;t<n;++t) l[0][t]=(i&(1<<t))?1:0;
					for(int t=0;t<n;++t) l[1][t]=(j&(1<<t))?1:0;
					for(int t=0;t<n;++t) l[2][t]=(k&(1<<t))?1:0;
					bool f=1;
					for(int t=0;t<n;++t){
						if(!l[1][t]) continue;
						int s=l[1][(t-1+n)%n]+l[1][(t+1)%n]+l[0][t]+l[2][t];
						if(s!=3){ f=0; break; }
					}
					o[i][j][k]=f; if(f) v[i][j][c[i][j]++]=k;
				}
		dfs(0,0);
	}
	puts("-1 -1"); return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3

output:

3 1
#
#
.

result:

ok good solution

Test #2:

score: 0
Accepted
time: 124ms
memory: 5888kb

input:

1 1

output:

-1 -1

result:

ok no solution

Test #3:

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

input:

3 4

output:

4 4
#.##
#.##
###.
###.

result:

ok good solution

Test #4:

score: 0
Accepted
time: 1ms
memory: 5848kb

input:

3 5

output:

10 1
#
#
.
.
#
#
.
#
#
.

result:

ok good solution

Test #5:

score: 0
Accepted
time: 21ms
memory: 4588kb

input:

4 5

output:

5 5
###.#
.####
##.##
####.
#.###

result:

ok good solution

Test #6:

score: 0
Accepted
time: 2ms
memory: 4280kb

input:

7 10

output:

5 4
##..
##..
####
..##
####

result:

ok good solution

Test #7:

score: 0
Accepted
time: 3ms
memory: 4052kb

input:

5 7

output:

14 4
##..
####
..##
####
##..
##..
####
..##
####
##..
####
..##
####
##..

result:

ok good solution

Test #8:

score: 0
Accepted
time: 34ms
memory: 6692kb

input:

7 9

output:

18 6
#####.
###.##
..####
####.#
##.###
.####.
###.##
#.####
####..
##.###
.#####
###..#
#.####
#####.
##..##
.#####
####.#
#..###

result:

ok good solution

Test #9:

score: -100
Wrong Answer
time: 5ms
memory: 6152kb

input:

0 1

output:

-1 -1

result:

wrong answer you didn't find a solution but jury did