QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#124636 | #4327. Šeširi | He_Ren | 100 ✓ | 22ms | 15200kb | C++17 | 1.8kb | 2023-07-15 11:35:45 | 2023-07-15 11:35:48 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define bbit(i) (1<<(i))
#define bdig(x,i) (((x)>>(i))&1)
int getdel(int mask,int i)
{
int t = mask >> (i+1);
return mask ^ (t << (i+1)) ^ (t << i);
}
vector< vector<int> > getres(int n)
{
if(n == 2) return {{0,1}, {1,0}};
if(n % 2 == 1)
{
auto a = getres(n - 1);
vector< vector<int> > res(n, vector<int>(1 << (n-1)));
for(int i=0; i<n-1; ++i)
for(int mask=0; mask<(1<<(n-1)); ++mask)
res[i][mask] = a[i][mask & (bbit(n-2) - 1)];
for(int mask=0; mask<(1<<(n-1)); ++mask)
{
int cnt = 0, ok = 0;
for(int i=0; i<n-1; ++i)
if(bdig(mask, i) == 0)
{
++cnt;
if(a[i][getdel(mask, i)] == 0)
++ok;
}
res[n-1][mask] = ok == cnt / 2? 0: 1;
}
return res;
}
auto a = getres(n - 2);
vector< vector<int> > res(n, vector<int>(1 << (n-1)));
for(int i=0; i<n-2; ++i)
for(int mask=0; mask<(1<<(n-1)); ++mask)
{
res[i][mask] = a[i][mask & (bbit(n-3) - 1)];
if(bdig(mask,n-3) != bdig(mask,n-2) && bdig(mask,n-2) == 0)
res[i][mask] ^= 1;
}
for(int mask=0; mask<(1<<(n-1)); ++mask)
{
int cnt = 0, ok = 0;
for(int i=0; i<n-2; ++i)
if(bdig(mask, i) == 0)
{
++cnt;
int tmask = mask & (bbit(n-2) - 1);
if(a[i][getdel(tmask, i)] == 0)
++ok;
}
int flag = cnt % 2 == 1 && ok == cnt / 2;
res[n-2][mask] = bdig(mask,n-2) ^ flag;
res[n-1][mask] = bdig(mask,n-2) ^ 1 ^ flag;
}
return res;
}
int main(void)
{
int n;
scanf("%d",&n);
auto ans = getres(n);
reverse(ans.begin(), ans.end());
for(int i=0; i<n; ++i, printf("\n"))
{
for(int j=0; j<(1<<(n-1)); ++j)
putchar(ans[i][j] + 'B');
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 1ms
memory: 3632kb
input:
4
output:
CCBCBBCB BBCBCCBC CBBCCBCB BCCBBCBC
result:
ok good plan!
Subtask #2:
score: 7
Accepted
Test #2:
score: 7
Accepted
time: 1ms
memory: 3600kb
input:
5
output:
BCBBCBBCBBBBBCBB CCBCBBCBCCBCBBCB BBCBCCBCBBCBCCBC CBBCCBCBCBBCCBCB BCCBBCBCBCCBBCBC
result:
ok good plan!
Subtask #3:
score: 7
Accepted
Test #3:
score: 7
Accepted
time: 1ms
memory: 3604kb
input:
6
output:
CCBCCCCCBCCBCCBCBBCBBBBBCBBCBBCB BBCBBBBBCBBCBBCBCCBCCCCCBCCBCCBC CCBCBBCBBBCBCCBCCCBCBBCBCCBCBBCB BBCBCCBCCCBCBBCBBBCBCCBCBBCBCCBC CBBCCBCBBCCBBCBCCBBCCBCBCBBCCBCB BCCBBCBCCBBCCBCBBCCBBCBCBCCBBCBC
result:
ok good plan!
Subtask #4:
score: 7
Accepted
Test #4:
score: 7
Accepted
time: 0ms
memory: 3628kb
input:
7
output:
BCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBB CCBCCCCCBCCBCCBCBBCBBBBBCBBCBBCBCCBCCCCCBCCBCCBCBBCBBBBBCBBCBBCB BBCBBBBBCBBCBBCBCCBCCCCCBCCBCCBCBBCBBBBBCBBCBBCBCCBCCCCCBCCBCCBC CCBCBBCBBBCBCCBCCCBCBBCBCCBCBBCBCCBCBBCBBBCBCCBCCCBCBBCBCCBCBBCB BBCBCCBCCCBCBBCBBBCBCCBCBBCBCCBCBBCBCCBC...
result:
ok good plan!
Subtask #5:
score: 7
Accepted
Test #5:
score: 7
Accepted
time: 1ms
memory: 3532kb
input:
8
output:
CCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCBBCBBBBBCBBCBBCBBBBBBBBBBBBBBBBBCBBCBCCBBCCBCBBCBBCBBBBBCBBCBBCB BBCBBBBBCBBCBBCBBBBBBBBBBBBBBBBBCBBCBCCBBCCBCBBCBBCBBBBBCBBCBBCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBC CCBCCCCCBCCBCCBCBBCBBBBBCBBCBBCBBBCBBBBBCB...
result:
ok good plan!
Subtask #6:
score: 7
Accepted
Test #6:
score: 7
Accepted
time: 1ms
memory: 3680kb
input:
9
output:
BCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBB CCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBB...
result:
ok good plan!
Subtask #7:
score: 7
Accepted
Test #7:
score: 7
Accepted
time: 1ms
memory: 3604kb
input:
10
output:
CCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCBBCBBBBBCBBCBBCBBBBBBBBBBBBBBBBBCBBCBCCBBCCB...
result:
ok good plan!
Subtask #8:
score: 7
Accepted
Test #8:
score: 7
Accepted
time: 1ms
memory: 3648kb
input:
11
output:
BCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBC...
result:
ok good plan!
Subtask #9:
score: 7
Accepted
Test #9:
score: 7
Accepted
time: 1ms
memory: 3760kb
input:
12
output:
CCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC...
result:
ok good plan!
Subtask #10:
score: 7
Accepted
Test #10:
score: 7
Accepted
time: 2ms
memory: 3736kb
input:
13
output:
BCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBC...
result:
ok good plan!
Subtask #11:
score: 6
Accepted
Test #11:
score: 6
Accepted
time: 0ms
memory: 3948kb
input:
14
output:
CCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC...
result:
ok good plan!
Subtask #12:
score: 6
Accepted
Test #12:
score: 6
Accepted
time: 5ms
memory: 4856kb
input:
15
output:
BCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBC...
result:
ok good plan!
Subtask #13:
score: 6
Accepted
Test #13:
score: 6
Accepted
time: 8ms
memory: 5636kb
input:
16
output:
CCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC...
result:
ok good plan!
Subtask #14:
score: 6
Accepted
Test #14:
score: 6
Accepted
time: 13ms
memory: 10032kb
input:
17
output:
BCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBBBBBBBBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBC...
result:
ok good plan!
Subtask #15:
score: 6
Accepted
Test #15:
score: 6
Accepted
time: 22ms
memory: 15200kb
input:
18
output:
CCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCBBCBCCBBCCBCBBCCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBCCBCBBCCBBCBCCBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCC...
result:
ok good plan!
Extra Test:
score: 0
Extra Test Passed