QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#150657 | #4327. Šeširi | penguinman | 0 | 1166ms | 37996kb | C++17 | 2.7kb | 2023-08-25 23:31:12 | 2023-08-25 23:31:14 |
Judging History
answer
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using pii = std::pair<ll,ll>;
#define rep(i,j,k) for(ll i=ll(j); i<ll(k); i++)
#define REP(i,j,k) for(ll i=ll(j); i<=ll(k); i++)
#define per(i,j,k) for(ll i=ll(j); i>=ll(k); i--)
#define ln "\n"
#define pb emplace_back
#define mp std::make_pair
#define mtp std::make_tuple
#define all(a) a.begin(),a.end()
constexpr ll inf = 1e18;
int main(){
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
ll N; cin >> N;
vii edge((2<<N)+1), weight((2<<N)+1);
vi idx, bit;
ll M = 0;
rep(i,0,1<<N){
rep(j,0,N){
if(i & (1<<j)){
ll now = i;
ll next = i^(1<<j);
edge[now*2].pb(next*2+1);
weight[now*2].pb(M);
edge[next*2+1].pb(now*2);
weight[next*2+1].pb(M);
ll val = 0;
val += (i&((1<<j)-1));
val += ((i>>(j+1))<<j);
assert(0 <= val && val < ((1<<(N-1))));
idx.pb(j);
bit.pb(val);
M++;
}
}
}
rep(i,0,2<<N){
if(edge[i].size()%2){
edge[i].pb((2<<N));
weight[i].pb(M);
edge[(2<<N)].pb(i);
weight[(2<<N)].pb(M);
M++;
}
}
assert(edge[2<<N].size()%2 == 0);
vector<string> ans(N, string(1<<(N-1),'A'));
vector<bool> used(M);
vector<bool> visited((2<<N)+1);
std::function<void(ll)> dfs = [&](ll now){
visited[now] = true;
rep(i,0,edge[now].size()){
ll next = edge[now][i];
ll m = weight[now][i];
if(used[m]) continue;
used[m] = true;
dfs(next);
if(m >= idx.size()) continue;
if(now%2){
assert(next%2 == 0);
ans[idx[m]][bit[m]] = 'B';
}
else{
assert(next%2);
ans[idx[m]][bit[m]] = 'C';
}
}
};
REP(i,0,2<<N){
if(visited[i]) continue;
dfs(i);
}
rep(i,0,1<<N){
vi sum(2), ok(2);
rep(j,0,N){
ll val = 0;
val += (i&((1<<j)-1));
val += ((i>>(j+1))<<j);
if(i&(1<<j)){
sum[1]++;
if(ans[j][val] == 'C') ok[1]++;
}
else{
sum[0]++;
if(ans[j][val] == 'B') ok[0]++;
}
}
}
rep(i,0,N){
reverse(all(ans[i]));
cout << ans[i] << ln;
}
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3436kb
input:
4
output:
CBCCCBCB CCBBCCBC BBCCBBCB BBBBCCBC
result:
wrong answer your plan fails on CCCC
Subtask #2:
score: 0
Wrong Answer
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 3492kb
input:
5
output:
CBCCBBCBCBCCCBCB CCBBCCBCBCBBBCBB BBCCBBCBCBCCBBCC BCBBCCBCBBCBCCBB BBCBBBBBCBBCBBCC
result:
wrong answer your plan fails on CCCCC
Subtask #3:
score: 0
Wrong Answer
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 3532kb
input:
6
output:
CBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCB CCBBCCBCBCBBCCBBCCBBCCBCBCBBCCBC CBCCBBCBCBCCBBCCCBCCBBCBCBCCBBCB BCBCCCCCBBBBCCBBBCBCCCCCBBBBCCBC BBCBBCBBCCCCCBCCBBCBBCBBCCCCCBCB BBBBBBBBCBBBBBBBCCCCBBCCBBBBBCBC
result:
wrong answer your plan fails on CCBBBB
Subtask #4:
score: 0
Wrong Answer
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 3480kb
input:
7
output:
CBCCBBCBCBCCCBCCBCBCCBCBBBCCBBCBCBCBBBCBCBCCCBCCCBCCBBCBCBCCCBCB CCBBCCBCBCBBCCBBCBCBBCBCCCBBCCBCBCBCCCBCBCBBBCBBCCBBCCBCBCBBBCBB CBCCBBCCCBCBBBCCBCBCBBCBCBCCBBCBCBCBBBCBCBCCCBCCBBCCBBCBCBCCBBCC BCBCCCCBBBBCCCBBCBCBCCBCBCBBCCBCBCBCCBCCBBCBBCBBBCBBCCBCBBCBCCBB BBCBBCBCCCCBCBCCBCBCBBBBCBBCBBCBCBCBBCCB...
result:
wrong answer your plan fails on CCCCCCB
Subtask #5:
score: 0
Wrong Answer
Test #5:
score: 0
Wrong Answer
time: 1ms
memory: 3648kb
input:
8
output:
CBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCB CCBBCCBCBCBBCCBBCCBCCCBCBCBBCCBCBCBBCCBCBBCBBCBBCCBBCCBCBCBBCCBBCCBBCCBCBCBBCCBBCCBCCCBCBCBBCCBCBCBBCCBCBCBBBCBBCCBBCCBCBCBBCCBC CBCCBBCBCBCCBBCCBBCBBBCBCBCCBBCBCBCCBBCBCC...
result:
wrong answer your plan fails on CCBBBBBB
Subtask #6:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 2ms
memory: 3804kb
input:
9
output:
CBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCCBBCCCBCCBBCBCBCCCBCBBBCBCCBCCBCBBBCCBBCBCBCCBBCCBCBBCBCBBBCCBBCBCBCBBBCBCBCCBBCBBBCBBBCCCBCBBBCBCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCCBCBCCBCBBBCCBBCBCBCBBBCBCBCCCBCCCBCCBBCBCBCCCBCB CCBBCCBCBCBBCCBBCCBCCCBCBCBBCCBCBCBBCCBCBCB...
result:
wrong answer your plan fails on CCCCCBBBB
Subtask #7:
score: 0
Wrong Answer
Test #7:
score: 0
Wrong Answer
time: 3ms
memory: 4488kb
input:
10
output:
CBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBBBCBBBCBCBCCBBCBCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCBBCBBBCBCBCCBBCBCCBCCBCCBCBBCBCCCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBC...
result:
wrong answer your plan fails on CCBBBBBBBB
Subtask #8:
score: 0
Wrong Answer
Test #8:
score: 0
Wrong Answer
time: 9ms
memory: 5024kb
input:
11
output:
CBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBBBCBBBCCCBCBBCBBCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCCBBCCCBCCBBCBCBCBCBCBBBCCCBCBBCBCBBCCBBCBCCBC...
result:
wrong answer your plan fails on CCCCCBBBBBB
Subtask #9:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 21ms
memory: 7920kb
input:
12
output:
CBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBBBCBBBCBCBCCBBCBCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCBBCBBBCBCBCCBBCBCCBCCBCCBCBBCBCCCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBBBCBBBCBCBCCBBCBCBCCBBCBCCBC...
result:
wrong answer your plan fails on CCBBBBBBBBBB
Subtask #10:
score: 0
Wrong Answer
Test #10:
score: 0
Wrong Answer
time: 81ms
memory: 10968kb
input:
13
output:
CBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBBBCBBBCCCBCBBCBBCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCBBCBBBCBCBCCBBCBCCBCCBCBBCBCCBCCCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCCBCCBBCCCBCBCCBCBBCBBBCBCBCCBBCBBBCBBBCCCBCBBCBBCBCCBBCBCCBC...
result:
wrong answer your plan fails on CCCCCBBBBBBBB
Subtask #11:
score: 0
Wrong Answer
Test #11:
score: 0
Wrong Answer
time: 317ms
memory: 24944kb
input:
14
output:
CBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBBBCBBBCBCBCCBBCBCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCBBCBBBCBCBCCBBCBCCBCCBCCBCBBCBCCCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCBCCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBBBCBBBCBCBCCBBCBCBCCBBCBCCBC...
result:
wrong answer your plan fails on CCBBBBBBBBBBBB
Subtask #12:
score: 0
Wrong Answer
Test #12:
score: 0
Wrong Answer
time: 1166ms
memory: 37996kb
input:
15
output:
CBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCCCBCCBBCBCCBCCBCBCBCCBBCCCBCBCCBCBBCBBBCBCBCCBBCCBBCBBBCCCBCBBCBBCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCBBBCBBBCCCBCBBCBBCCBCCBCCBCBBCBCCCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCBCBCCBBCBCCBCCBCCCBCCBBCBCBCCCBCCBBCBBBCBCBCCBBCCBBCBBBCCCBCBBCBBCBCCBBCBCCBC...
result:
wrong answer your plan fails on CCCCCBBBBBBBBBB
Subtask #13:
score: 0
Time Limit Exceeded
Test #13:
score: 0
Time Limit Exceeded
input:
16
output:
result:
Subtask #14:
score: 0
Time Limit Exceeded
Test #14:
score: 0
Time Limit Exceeded
input:
17
output:
result:
Subtask #15:
score: 0
Time Limit Exceeded
Test #15:
score: 0
Time Limit Exceeded
input:
18