QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#514767#7637. Exactly Three NeighborsAlex_wcqAC ✓1164ms6500kbC++141.1kb2024-08-11 10:09:312024-08-11 10:09:32

Judging History

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

  • [2024-08-11 10:09:32]
  • 评测
  • 测评结果:AC
  • 用时:1164ms
  • 内存:6500kb
  • [2024-08-11 10:09:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m=20,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*2<p*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: 3784kb

input:

2 3

output:

3 1
#
#
.

result:

ok good solution

Test #2:

score: 0
Accepted
time: 307ms
memory: 5864kb

input:

1 1

output:

-1 -1

result:

ok no solution

Test #3:

score: 0
Accepted
time: 13ms
memory: 4028kb

input:

3 4

output:

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

result:

ok good solution

Test #4:

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

input:

3 5

output:

20 1
#
#
.
.
#
#
.
.
#
#
.
#
#
.
#
#
.
#
#
.

result:

ok good solution

Test #5:

score: 0
Accepted
time: 155ms
memory: 6188kb

input:

4 5

output:

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

result:

ok good solution

Test #6:

score: 0
Accepted
time: 37ms
memory: 5976kb

input:

7 10

output:

20 4
####
..##
####
##..
####
..##
####
##..
####
..##
####
##..
##..
##..
####
..##
..##
..##
####
##..

result:

ok good solution

Test #7:

score: 0
Accepted
time: 93ms
memory: 4032kb

input:

5 7

output:

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

result:

ok good solution

Test #8:

score: 0
Accepted
time: 512ms
memory: 6312kb

input:

7 9

output:

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

result:

ok good solution

Test #9:

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

input:

0 1

output:

3 1
.
.
.

result:

ok good solution

Test #10:

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

input:

1 2

output:

4 1
#
#
.
.

result:

ok good solution

Test #11:

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

input:

1 3

output:

6 1
#
#
.
.
.
.

result:

ok good solution

Test #12:

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

input:

1 4

output:

8 1
#
#
.
.
.
.
.
.

result:

ok good solution

Test #13:

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

input:

1 5

output:

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

result:

ok good solution

Test #14:

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

input:

1 6

output:

12 1
#
#
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #15:

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

input:

1 7

output:

14 1
#
#
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #16:

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

input:

1 8

output:

16 1
#
#
.
.
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #17:

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

input:

1 9

output:

18 1
#
#
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #18:

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

input:

1 10

output:

20 1
#
#
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.
.

result:

ok good solution

Test #19:

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

input:

2 5

output:

5 1
#
#
.
.
.

result:

ok good solution

Test #20:

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

input:

2 7

output:

7 1
#
#
.
.
.
.
.

result:

ok good solution

Test #21:

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

input:

2 9

output:

9 1
#
#
.
.
.
.
.
.
.

result:

ok good solution

Test #22:

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

input:

3 7

output:

14 1
#
#
.
.
.
.
.
#
#
.
#
#
.
.

result:

ok good solution

Test #23:

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

input:

3 8

output:

16 1
#
#
.
.
.
.
.
#
#
.
#
#
.
.
.
.

result:

ok good solution

Test #24:

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

input:

3 10

output:

20 1
#
#
.
.
.
.
.
#
#
.
#
#
.
.
.
.
.
.
.
.

result:

ok good solution

Test #25:

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

input:

4 7

output:

14 1
#
#
.
.
.
#
#
.
#
#
.
#
#
.

result:

ok good solution

Test #26:

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

input:

4 9

output:

18 1
#
#
.
.
.
.
.
#
#
.
#
#
.
.
#
#
.
.

result:

ok good solution

Test #27:

score: 0
Accepted
time: 1164ms
memory: 6492kb

input:

5 6

output:

-1 -1

result:

ok no solution

Test #28:

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

input:

5 8

output:

16 1
#
#
.
.
#
#
.
#
#
.
#
#
.
#
#
.

result:

ok good solution

Test #29:

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

input:

5 9

output:

18 1
#
#
.
.
.
#
#
.
#
#
.
#
#
.
.
#
#
.

result:

ok good solution

Test #30:

score: 0
Accepted
time: 445ms
memory: 6076kb

input:

6 7

output:

-1 -1

result:

ok no solution

Test #31:

score: 0
Accepted
time: 428ms
memory: 6152kb

input:

7 8

output:

-1 -1

result:

ok no solution

Test #32:

score: 0
Accepted
time: 420ms
memory: 6500kb

input:

8 9

output:

-1 -1

result:

ok no solution

Test #33:

score: 0
Accepted
time: 270ms
memory: 6180kb

input:

9 10

output:

-1 -1

result:

ok no solution

Extra Test:

score: 0
Extra Test Passed