QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#740637 | #2134. Balanced Illumination | zhouhuanyi | AC ✓ | 88ms | 6096kb | C++14 | 2.0kb | 2024-11-13 10:51:06 | 2024-11-13 10:51:07 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#define N 25
#define M 33554432
using namespace std;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
char obuf[1<<27],*O=obuf;
int n,b[N+1],c[N+1],cs[N+1];
bool used[M+1],vis[N+1];
vector<short>solve(int sn)
{
if (sn==1) return {1,1};
else if (sn==2) return {1,2,1,2};
else if (sn==3) return {1,3,1,2,1,3,1,2};
else
{
int cnt=0;
vector<short>p=solve(sn-2);
vector<short>sp;
vector<short>st;
int d=(1<<(sn-1))%sn,lst=-1;
for (int i=1;i<=sn-2;++i) c[i]=0;
for (int i=1;i<=sn-2;++i) cs[i]=((1<<(sn-1))/sn+(i<=d))<<1;
for (int i=0;i<p.size();++i) c[p[i]]++;
for (int i=1;i<=sn-2;++i) b[i]=(c[i]<<1)-(cs[i]>>1);
if (b[p.back()]<2)
{
for (int i=1;i<p.size();++i)
if (b[p[i-1]]>=2)
{
for (int j=0;j<p.size();++j) sp.push_back(p[(i+j)%p.size()]);
p=sp;
break;
}
}
b[p.back()]--;
for (int i=p.size()-1;i>=0;--i)
{
if (b[p[i]]) b[p[i]]--,used[i]=1;
else used[i]=0;
}
for (int i=0;i+1<p.size();++i)
if (used[i])
{
cnt++;
for (int j=lst+1;j<=i-1;++j) st.push_back(p[j]);
if (cnt&1) st.push_back(sn);
else st.push_back(sn-1);
for (int j=i-1;j>=lst+1;--j) st.push_back(p[j]);
if (cnt&1) st.push_back(sn-1);
else st.push_back(sn);
for (int j=lst+1;j<=i;++j) st.push_back(p[j]);
lst=i;
}
for (int i=lst+1;i+1<p.size();++i) st.push_back(p[i]);
st.push_back(sn);
for (int i=p.size()-2;i>=lst+1;--i) st.push_back(p[i]);
st.push_back(sn-1);
for (int i=lst+1;i+1<p.size();++i) st.push_back(p[i]);
st.push_back(sn);
for (int i=p.size()-2;i>=0;--i) st.push_back(p[i]);
st.push_back(sn-1);
return st;
}
}
int main()
{
vector<short>p;
n=read(),p=solve(n);
for (int i=0;i<p.size();++i)
{
for (int j=1;j<=n;++j) printf("%d",vis[j]);
puts("");
vis[p[i]]^=1;
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 5724kb
input:
3
output:
000 100 101 001 011 111 110 010
result:
ok n = 3, mihch = 2, maxch = 4
Test #2:
score: 0
Accepted
time: 1ms
memory: 5716kb
input:
4
output:
0000 0001 0011 1011 1111 1101 1001 1000 1100 0100 0101 0111 0110 1110 1010 0010
result:
ok n = 4, mihch = 4, maxch = 4
Test #3:
score: 0
Accepted
time: 1ms
memory: 5840kb
input:
1
output:
0 1
result:
ok n = 1, mihch = 2, maxch = 2
Test #4:
score: 0
Accepted
time: 1ms
memory: 6036kb
input:
2
output:
00 10 11 01
result:
ok n = 2, mihch = 2, maxch = 2
Test #5:
score: 0
Accepted
time: 1ms
memory: 5848kb
input:
5
output:
00000 00100 10100 11100 11101 10101 00101 00001 00011 00111 10111 11111 01111 01101 01100 01000 01001 01011 11011 11001 11000 10000 10001 10011 10010 11010 01010 01110 11110 10110 00110 00010
result:
ok n = 5, mihch = 6, maxch = 8
Test #6:
score: 0
Accepted
time: 1ms
memory: 5964kb
input:
6
output:
000000 000100 001100 101100 111100 110100 100100 100101 110101 111101 101101 001101 000101 000001 000011 000111 001111 101111 111111 110111 100111 100011 100001 100000 110000 010000 010001 110001 110011 010011 010111 010101 010100 011100 011101 011111 011011 011001 011000 111000 111001 111011 101011...
result:
ok n = 6, mihch = 10, maxch = 12
Test #7:
score: 0
Accepted
time: 1ms
memory: 5828kb
input:
7
output:
0000000 0010000 1010000 1110000 1110100 1010100 0010100 0000100 0001100 0011100 0011101 0001101 0000101 0010101 1010101 1110101 1110001 1010001 0010001 0000001 0000011 0010011 1010011 1110011 1110111 1010111 0010111 0000111 0001111 0011111 1011111 1111111 1111101 1011101 1011100 1111100 0111100 0110...
result:
ok n = 7, mihch = 18, maxch = 20
Test #8:
score: 0
Accepted
time: 1ms
memory: 6096kb
input:
8
output:
00000000 00010000 00110000 10110000 11110000 11010000 10010000 10010100 11010100 11110100 10110100 00110100 00010100 00000100 00001100 00011100 00111100 10111100 10111101 00111101 00011101 00001101 00000101 00010101 00110101 10110101 11110101 11010101 10010101 10010001 11010001 11110001 10110001 001...
result:
ok n = 8, mihch = 32, maxch = 32
Test #9:
score: 0
Accepted
time: 0ms
memory: 5992kb
input:
9
output:
000000000 001000000 101000000 111000000 111010000 101010000 001010000 000010000 000110000 001110000 001110100 000110100 000010100 001010100 101010100 111010100 111000100 101000100 001000100 000000100 000001100 001001100 101001100 111001100 111011100 101011100 001011100 000011100 000111100 001111100 ...
result:
ok n = 9, mihch = 56, maxch = 58
Test #10:
score: 0
Accepted
time: 1ms
memory: 6036kb
input:
10
output:
0000000000 0001000000 0011000000 1011000000 1111000000 1101000000 1001000000 1001010000 1101010000 1111010000 1011010000 0011010000 0001010000 0000010000 0000110000 0001110000 0011110000 1011110000 1011110100 0011110100 0001110100 0000110100 0000010100 0001010100 0011010100 1011010100 1111010100 110...
result:
ok n = 10, mihch = 102, maxch = 104
Test #11:
score: 0
Accepted
time: 1ms
memory: 6044kb
input:
11
output:
00000000000 00100000000 10100000000 11100000000 11101000000 10101000000 00101000000 00001000000 00011000000 00111000000 00111010000 00011010000 00001010000 00101010000 10101010000 11101010000 11100010000 10100010000 00100010000 00000010000 00000110000 00100110000 10100110000 11100110000 11101110000 ...
result:
ok n = 11, mihch = 186, maxch = 188
Test #12:
score: 0
Accepted
time: 0ms
memory: 5772kb
input:
12
output:
000000000000 000100000000 001100000000 101100000000 111100000000 110100000000 100100000000 100101000000 110101000000 111101000000 101101000000 001101000000 000101000000 000001000000 000011000000 000111000000 001111000000 101111000000 101111010000 001111010000 000111010000 000011010000 000001010000 0...
result:
ok n = 12, mihch = 340, maxch = 342
Test #13:
score: 0
Accepted
time: 2ms
memory: 5860kb
input:
13
output:
0000000000000 0010000000000 1010000000000 1110000000000 1110100000000 1010100000000 0010100000000 0000100000000 0001100000000 0011100000000 0011101000000 0001101000000 0000101000000 0010101000000 1010101000000 1110101000000 1110001000000 1010001000000 0010001000000 0000001000000 0000011000000 001001...
result:
ok n = 13, mihch = 630, maxch = 632
Test #14:
score: 0
Accepted
time: 10ms
memory: 5900kb
input:
14
output:
00000000000000 00010000000000 00110000000000 10110000000000 11110000000000 11010000000000 10010000000000 10010100000000 11010100000000 11110100000000 10110100000000 00110100000000 00010100000000 00000100000000 00001100000000 00011100000000 00111100000000 10111100000000 10111101000000 00111101000000 ...
result:
ok n = 14, mihch = 1170, maxch = 1172
Test #15:
score: 0
Accepted
time: 20ms
memory: 5840kb
input:
15
output:
000000000000000 001000000000000 101000000000000 111000000000000 111010000000000 101010000000000 001010000000000 000010000000000 000110000000000 001110000000000 001110100000000 000110100000000 000010100000000 001010100000000 101010100000000 111010100000000 111000100000000 101000100000000 001000100000...
result:
ok n = 15, mihch = 2184, maxch = 2186
Test #16:
score: 0
Accepted
time: 39ms
memory: 5952kb
input:
16
output:
0000000000000000 0001000000000000 0011000000000000 1011000000000000 1111000000000000 1101000000000000 1001000000000000 1001010000000000 1101010000000000 1111010000000000 1011010000000000 0011010000000000 0001010000000000 0000010000000000 0000110000000000 0001110000000000 0011110000000000 10111100000...
result:
ok n = 16, mihch = 4096, maxch = 4096
Test #17:
score: 0
Accepted
time: 88ms
memory: 5964kb
input:
17
output:
00000000000000000 00100000000000000 10100000000000000 11100000000000000 11101000000000000 10101000000000000 00101000000000000 00001000000000000 00011000000000000 00111000000000000 00111010000000000 00011010000000000 00001010000000000 00101010000000000 10101010000000000 11101010000000000 111000100000...
result:
ok n = 17, mihch = 7710, maxch = 7712