QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#150687 | #4327. Šeširi | penguinman | 100 ✓ | 773ms | 252244kb | C++17 | 3.0kb | 2023-08-26 00:42:09 | 2023-08-26 00:42:12 |
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;
ll l = 0;
per(k,N-1,0){
if(k == j) continue;
if(i&(1<<k)){
val += (1<<l);
}
l++;
}
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;
while(!edge[now].empty()){
ll next = edge[now].back();
ll m = weight[now].back();
edge[now].pop_back();
weight[now].pop_back();
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){
cout << ans[i] << ln;
}
}
详细
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 1ms
memory: 3424kb
input:
4
output:
CBCCBBBB BCBBCCBB CBCCBBCC BCBCCCBC
result:
ok good plan!
Subtask #2:
score: 7
Accepted
Test #2:
score: 7
Accepted
time: 1ms
memory: 3412kb
input:
5
output:
CCBBCCCCBBBBBCBB BBCCBBBBCCCCBBCB CCBBCCCCBBBBCCBC BBCCBBCBCCCCBBCC CCBCCCCCBCCBCCBC
result:
ok good plan!
Subtask #3:
score: 7
Accepted
Test #3:
score: 7
Accepted
time: 1ms
memory: 3448kb
input:
6
output:
CBCCBBBBCCCCCCCCBBBBBBBBBBCBBCBB BCBBCCCCBBBBBBBBCCCCCCCCBBBCCBBB CBCCBBBBCCCCCCCCBBBBBBBBCCBBCCBB BCBBCCBBBBBBCCBCCCBBCCCBBBCCBBCC CBCCBBCCCCBBBBCBBBCCBBBCBBBBCCCC BCBCCCBCBCCCCCBCCCBCCCBCCCCCCBBC
result:
ok good plan!
Subtask #4:
score: 7
Accepted
Test #4:
score: 7
Accepted
time: 0ms
memory: 3576kb
input:
7
output:
CCBBCCCBBBBCBBCBCCCBCCCCCCCCCCCCBBBCBBBBBBBBBBBBBCBBCCBCBBCBBCBB BBCCBBBCCCCBCCBCBBBCBBBBBBBBBBBBCCCBCCCCCCCCCCCCBBCBBBCBCCBCBBCB CCBBCCCBBBBCBCBBCCCBCCCCCCCCCCCCBBBCBBBBBBBBBBBBCCBCCBBCBCCBBCBB BBCCBBBCCCCBBBCBBBBCBBCBCBCCBBCBCCCBBCBBCCBCCCBCBBCBBCCBCBBCCBCC CCBBCCCBBBBCCCBCCCCBBCBBBCBBCCBCBBBCCCBC...
result:
ok good plan!
Subtask #5:
score: 7
Accepted
Test #5:
score: 7
Accepted
time: 1ms
memory: 3632kb
input:
8
output:
CBCCBBBBCCCCCCBBBBBBBBCCBBBBCCBBCCCCCCBBCCCCCCCCCCCCCCCCCCCCCCCCBBBBBBCCBBBBBBBBBBBBBBBBBBBBBBBBBBCCBBBBCCCCBBCCBBBBCCBBBBCBBCBB BCBBCCCCBBBBBBCCCCCCCCBBCCCCBBCCBBBBBBCCBBBBBBBBBBBBBBBBBBBBBBBBCCCCCCBBCCCCCCCCCCCCCCCCCCCCCCCCBBBBCCBBBBBBCCBBCCCCBBCCBBBCCBBB CBCCBBBBCCCCCCBBBBBBBBCCBBCCBBBBCCCCCCBBCC...
result:
ok good plan!
Subtask #6:
score: 7
Accepted
Test #6:
score: 7
Accepted
time: 2ms
memory: 3744kb
input:
9
output:
CCBBCCCBBBBCBBCBCCCBCCCCCBBCBBBBBBBCBBBBBCCBCCCCBBCBBBBCCCCBBBCBCCCBCCCCCBBCBBBBCCBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCBBCCCCCCCCCBBBCBBBBBCCBCCCCBBCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCBBBBBBBBBBCBBCCCCBBBBBCBBCCCCCBBCBCCBCCCCBBBBBCCBCBBCBBBBBCBBCCBCBBCBBCBB BBCCBBBCCCCBCCBCBBBCBBBBBCCBCCCCCCCBCCCCCBB...
result:
ok good plan!
Subtask #7:
score: 7
Accepted
Test #7:
score: 7
Accepted
time: 2ms
memory: 4108kb
input:
10
output:
CBCCBBBBCCCCCCBBBBBBBBCCBBBBCCBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBBBBCCCCCCCCBBBBBBCCBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBCCCCBBCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCBBBBCCCCCCCCCCCCCCCCCCBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBB...
result:
ok good plan!
Subtask #8:
score: 7
Accepted
Test #8:
score: 7
Accepted
time: 4ms
memory: 4548kb
input:
11
output:
CCBBCCCBBBBCBBCBCCCBCCCCCBBCBBBBBBBCBBBBBCCBCCCCBBCBBBBCCCCBBCBBCCCBCCCCCBBCBBBBCCBCCCCCCCCCCCBCCBBCBBBBBBBBCCCCBBBBBBBBBBBBBBBBBBBCBBBBBCCBCCCCBBCBBBBBBBBBBBCBBCCBCCCCCCCCBBBBCCCCCCCCCCCCCCCCBBCBBBBCCCCBBBCBBBBCBBBBBCCBCCCCCCCBCCCCCBBCBBBBBBCBBBBCCCCBBBCBCCCBCCCCCBBCBBBBCCBCCCCCCCCCCCCCCBBCBBBBBBBB...
result:
ok good plan!
Subtask #9:
score: 7
Accepted
Test #9:
score: 7
Accepted
time: 0ms
memory: 6076kb
input:
12
output:
CBCCBBBBCCCCCCBBBBBBBBCCBBBBCCBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBBBBCCCCCCCCBBBBCCBBBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBCCCCBBCCCCCCCCCCCCCCCCCCCCCCBBCCCCBBBBCCBBBBBBBBBBBBBBBBCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBB...
result:
ok good plan!
Subtask #10:
score: 7
Accepted
Test #10:
score: 7
Accepted
time: 9ms
memory: 8932kb
input:
13
output:
CCBBCCCBBBBCBBCBCCCBCCCCCBBCBBBBBBBCBBBBBCCBCCCCBBCBBBBBCCCCBCBBCCCBCCCCCBBCBBBBCCBCCCCCCCCCCCBCCBBCBBBBBBBBCCCCBBBBBBBBBBBBBBBBBBBCBBBBBCCBCCCCBBCBBBBBBBBBBBCBBCCBCCCCCCCCBBBBCCCCCCCCCCCCCCCCBBCBBBBBCCCCBBCBBBBBBBBBBCCBCCCBCCCCCCCCCBBCBBBCBCBBCCCBBBBCBBCBCCCBCCCCCBBCBBBBCCBCCCCCCCCCCCCCCBBCBBBBBBBB...
result:
ok good plan!
Subtask #11:
score: 6
Accepted
Test #11:
score: 6
Accepted
time: 22ms
memory: 16268kb
input:
14
output:
CBCCBBBBCCCCCCBBBBBBBBCCBBBBCCBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBBBBBBCCCCCCCCBBCCBBBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBCCCCBBCCCCCCCCCCCCCCCCCCCCCCBBCCCCBBBBCCBBBBBBBBBBBBBBBBCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBB...
result:
ok good plan!
Subtask #12:
score: 6
Accepted
Test #12:
score: 6
Accepted
time: 65ms
memory: 28412kb
input:
15
output:
CCBBCCCBBBBCBBCBCCCBCCCCCBBCBBBBBBBCBBBBBCCBCCCCBBCBBBBBCCCCBCBBCCCBCCCCCBBCBBBBCCBCCCCCCCCCCBCCCBBCBBBBBBBBCCBCBBBBBBBBBBBBBBBBBBBCBBBBBCCBCCCCBBCBBBBBBBBBBCBBBCCBCCCCCCCCBBCBCCCCCCCCCCCCCCCCBBCBBBBBCCCCBCBBBBBBBBBBBCCBBBBBCCCCCCCCCBBCCCCCBCBBCCCCBBBBBCBBCCCBCCCCCBBCBBBBCCBCCCCCCCCCCBCCCBBCBBBBBBBB...
result:
ok good plan!
Subtask #13:
score: 6
Accepted
Test #13:
score: 6
Accepted
time: 142ms
memory: 60792kb
input:
16
output:
CBCCBBBBCCCCCCBBBBBBBBCCBBBBCCBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBBBBBBCCCCCCCCBBCCBBBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBCCCCBBCCCCCCCCCCCCCCCCCCCCBBCCCCCCBBBBCCBBBBBBBBBBBBBBBBCCCCBBCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBB...
result:
ok good plan!
Subtask #14:
score: 6
Accepted
Test #14:
score: 6
Accepted
time: 342ms
memory: 115728kb
input:
17
output:
CCBBCCCBBBBCBBCBCCCBCCCCCBBCBBBBBBBCBBBBBCCBCCCCBBCBBBBBCCCCBCBBCCCBCCCCCBBCBBBBCCBCCCCCCCCCCBCCCBBCBBBBBBBBCCBCBBBBBBBBBBBBBBBBBBBCBBBBBCCBCCCCBBCBBBBBBBBBBCBBBCCBCCCCCCCCBBCBCCCCCCCCCCCCCCCCBBCBBBBBCCCCBCBBBBBBBBBBBCCBBBBBCCCCCCCCCBBCCCCCBBCBCCCCBBBBBCBBCCCBCCCCCBBCBBBBCCBCCCCCCCCCCBCCCBBCBBBBBBBB...
result:
ok good plan!
Subtask #15:
score: 6
Accepted
Test #15:
score: 6
Accepted
time: 773ms
memory: 252244kb
input:
18
output:
CBCCBBBBCCCCCCBBBBBBBBCCBBBBCCBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBBBBBBCCCCCCCCBBCCBBBBCCCCCCBBCCCCCCCCCCBBBBCCBBBBBBBBCCCCBBCCCCCCCCCCCCCCCCCCCCBBCCCCCCBBBBCCBBBBBBBBBBBBBBBBCCCCBBCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCBBBBBBBBBBCCCCBBCCCCCCCCBBBBCCBBBBBB...
result:
ok good plan!
Extra Test:
score: 0
Extra Test Passed