QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#514765 | #7637. Exactly Three Neighbors | Alex_wcq | TL | 296ms | 6352kb | C++14 | 1.2kb | 2024-08-11 10:06:50 | 2024-08-11 10:06:50 |
Judging History
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*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: 3880kb
input:
2 3
output:
3 1 # # .
result:
ok good solution
Test #2:
score: 0
Accepted
time: 123ms
memory: 5852kb
input:
1 1
output:
-1 -1
result:
ok no solution
Test #3:
score: 0
Accepted
time: 9ms
memory: 4032kb
input:
3 4
output:
4 4 ##.. #### ..## ####
result:
ok good solution
Test #4:
score: 0
Accepted
time: 0ms
memory: 3744kb
input:
3 5
output:
10 1 # # . . # # . # # .
result:
ok good solution
Test #5:
score: 0
Accepted
time: 32ms
memory: 4856kb
input:
4 5
output:
5 5 .#### ##.## ####. #.### ###.#
result:
ok good solution
Test #6:
score: 0
Accepted
time: 76ms
memory: 4332kb
input:
7 10
output:
5 4 #### ..## ..## #### ##..
result:
ok good solution
Test #7:
score: 0
Accepted
time: 4ms
memory: 4052kb
input:
5 7
output:
14 4 #### .##. .##. #### #..# #### .##. #### #..# #### .##. #### #..# #..#
result:
ok good solution
Test #8:
score: 0
Accepted
time: 296ms
memory: 6352kb
input:
7 9
output:
18 6 ####.. ##.### .##### ###..# #.#### #####. ##..## .##### ####.# #..### #####. ###.## ..#### ####.# ##.### .####. ###.## #.####
result:
ok good solution
Test #9:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
0 1
output:
3 1 . . .
result:
ok good solution
Test #10:
score: 0
Accepted
time: 0ms
memory: 3808kb
input:
1 2
output:
4 1 # # . .
result:
ok good solution
Test #11:
score: 0
Accepted
time: 0ms
memory: 3884kb
input:
1 3
output:
6 1 # # . . . .
result:
ok good solution
Test #12:
score: 0
Accepted
time: 1ms
memory: 5852kb
input:
1 4
output:
16 1 # # . . . . . # # . . . . . . .
result:
ok good solution
Test #13:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1 5
output:
10 1 # # . . . . . . . .
result:
ok good solution
Test #14:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
1 6
output:
12 1 # # . . . . . . . . . .
result:
ok good solution
Test #15:
score: 0
Accepted
time: 0ms
memory: 3788kb
input:
1 7
output:
14 1 # # . . . . . . . . . . . .
result:
ok good solution
Test #16:
score: 0
Accepted
time: 1ms
memory: 5780kb
input:
1 8
output:
16 1 # # . . . . . . . . . . . . . .
result:
ok good solution
Test #17:
score: 0
Accepted
time: 0ms
memory: 3812kb
input:
1 9
output:
18 1 # # . . . . . . . . . . . . . . . .
result:
ok good solution
Test #18:
score: -100
Time Limit Exceeded
input:
1 10