QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#514771#7637. Exactly Three NeighborsAlex_wcqAC ✓13ms6120kbC++141.2kb2024-08-11 10:13:312024-08-11 10:13:33

Judging History

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

  • [2024-08-11 10:13:33]
  • 评测
  • 测评结果:AC
  • 用时:13ms
  • 内存:6120kb
  • [2024-08-11 10:13:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
int n,m,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*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); if(p*5>q*4){ puts("-1 -1"); return 0; }
	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;
				}
		m=(n==1||n==6)?20:7; dfs(0,0);
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

2 3

output:

3 1
#
#
.

result:

ok good solution

Test #2:

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

input:

1 1

output:

-1 -1

result:

ok no solution

Test #3:

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

input:

3 4

output:

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

result:

ok good solution

Test #4:

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

input:

3 5

output:

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

result:

ok good solution

Test #5:

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

input:

4 5

output:

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

result:

ok good solution

Test #6:

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

input:

7 10

output:

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

result:

ok good solution

Test #7:

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

input:

5 7

output:

14 6
#...##
######
.###..
##.###
##.###
.###..
######
#...##
#####.
#####.
#...##
#...##
#####.
#####.

result:

ok good solution

Test #8:

score: 0
Accepted
time: 11ms
memory: 6052kb

input:

7 9

output:

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

result:

ok good solution

Test #9:

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

input:

0 1

output:

3 1
.
.
.

result:

ok good solution

Test #10:

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

input:

1 2

output:

4 1
#
#
.
.

result:

ok good solution

Test #11:

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

input:

1 3

output:

6 1
#
#
.
.
.
.

result:

ok good solution

Test #12:

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

input:

1 4

output:

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

result:

ok good solution

Test #13:

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

input:

1 5

output:

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

result:

ok good solution

Test #14:

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

input:

1 6

output:

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

result:

ok good solution

Test #15:

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

input:

1 7

output:

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

result:

ok good solution

Test #16:

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

input:

1 8

output:

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

result:

ok good solution

Test #17:

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

input:

1 9

output:

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

result:

ok good solution

Test #18:

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

input:

1 10

output:

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

result:

ok good solution

Test #19:

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

input:

2 5

output:

5 1
#
#
.
.
.

result:

ok good solution

Test #20:

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

input:

2 7

output:

7 1
#
#
.
.
.
.
.

result:

ok good solution

Test #21:

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

input:

2 9

output:

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

result:

ok good solution

Test #22:

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

input:

3 7

output:

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

result:

ok good solution

Test #23:

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

input:

3 8

output:

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

result:

ok good solution

Test #24:

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

input:

3 10

output:

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

result:

ok good solution

Test #25:

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

input:

4 7

output:

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

result:

ok good solution

Test #26:

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

input:

4 9

output:

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

result:

ok good solution

Test #27:

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

input:

5 6

output:

-1 -1

result:

ok no solution

Test #28:

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

input:

5 8

output:

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

result:

ok good solution

Test #29:

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

input:

5 9

output:

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

result:

ok good solution

Test #30:

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

input:

6 7

output:

-1 -1

result:

ok no solution

Test #31:

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

input:

7 8

output:

-1 -1

result:

ok no solution

Test #32:

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

input:

8 9

output:

-1 -1

result:

ok no solution

Test #33:

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

input:

9 10

output:

-1 -1

result:

ok no solution

Extra Test:

score: 0
Extra Test Passed