QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#150674 | #4327. Šeširi | penguinman | 82 | 817ms | 30264kb | C++17 | 2.2kb | 2023-08-26 00:03:28 | 2023-08-26 00:03:31 |
Judging History
answer
#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::endl;
using std::vector;
using std::string;
using ll = int;
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()
ll edge[1<<19][19], weight[1<<19][19];
ll sz[1<<19];
vector<bool> visited, used;
vector<string> ans;
ll N;
ll mem[1<<18];
void dfs(ll now){
visited[now] = true;
rep(i,0,sz[now]){
ll next = edge[now][i];
ll m = weight[now][i];
if(used[m]) continue;
used[m] = true;
dfs(next);
if(now == (2<<N) || next == (2<<N)) continue;
ll l = now/2, r = next/2;
ll idx = mem[l^r];
ll bit = (l&((1<<(idx))-1))+(l>>(idx+1)<<idx);
if(now%2){
ans[N-1-idx][bit] = 'B';
}
else{
ans[N-1-idx][bit] = 'C';
}
}
};
int main(){
cin.tie(nullptr);
std::ios::sync_with_stdio(false);
cin >> N;
rep(i,0,N) mem[1<<i] = i;
REP(i,0,2<<N) sz[i] = 0;
ll M = 0;
rep(i,0,1<<N){
rep(j,0,N){
if(i & (1<<j)){
ll now = i*2;
ll next = (i^(1<<j))*2+1;
edge[now][sz[now]] = next;
weight[now][sz[now]] = M;
edge[next][sz[next]] = now;
weight[next][sz[next]] = M;
sz[now]++;
sz[next]++;
M++;
}
}
}
rep(i,0,2<<N){
if(sz[i]%2){
edge[i][sz[i]] = (2<<N);
weight[i][sz[i]] = M;
edge[(2<<N)][sz[(2<<N)]] = i;
weight[(2<<N)][sz[(2<<N)]] = M;
sz[i]++;
sz[(2<<N)]++;
M++;
}
}
ans.resize(N, string(1<<(N-1),'A'));
used.resize(M);
visited.resize((2<<N)+1);
REP(i,0,2<<N){
if(visited[i]) continue;
dfs(i);
}
rep(i,0,N){
cout << ans[i] << ln;
}
}
詳細信息
Subtask #1:
score: 7
Accepted
Test #1:
score: 7
Accepted
time: 0ms
memory: 7676kb
input:
4
output:
CBCCBBBB BCBBCCBB CBCCBBCC BCBCCCBC
result:
ok good plan!
Subtask #2:
score: 7
Accepted
Test #2:
score: 7
Accepted
time: 2ms
memory: 7572kb
input:
5
output:
CCBBCBBCBBBBBCBB BBCCBCBBCBCCBBCB CCBBCCBCBCBBCCBB BBCBBBCBCBCCBBCC BCBCCCBCBCBBCCBC
result:
ok good plan!
Subtask #3:
score: 7
Accepted
Test #3:
score: 7
Accepted
time: 2ms
memory: 7616kb
input:
6
output:
CBCBBBBBCCBBCCCCBBBBBBBCBBBBBBBB BCBCCCCCBBCBBCBBCCBCCCCCBBCBBCBB CBCCBBBBCCCCCBCBBBCCBBBBCCCCCBCB BCBBCCBCBCBBCCBCCCBBCCBCBCBBCCBC CBCCBBCBCBCCBBCCBBCCBBCBCBCCBBCC BCBCCCBCBCBBCCBCCCBCCCBCBCBBCCBC
result:
ok good plan!
Subtask #4:
score: 7
Accepted
Test #4:
score: 7
Accepted
time: 1ms
memory: 9920kb
input:
7
output:
CCBBCBBCBBBBBCBBCBBCBCCBBCCBBBBCBBBBBBBBBBBBCBBBBBCBBBBCCBBBBCBB BBCCBCCBCCCCCBCCBCBBCBBCBBBCCBBBCBCCBCCBCCCBBCCCBCBBCBBBBBBCBBCB CCBBCBBCBBBBBCBBCCBCCCCCBCCBBCBCBCBBCBBCBBBBCBCBCCBCBCCCCBCBBCBB BBCCBCBBCBCCBBCBBBCBBCBBCCBCCBCBCBCCBBCBCBCCBCBCBBCCCBBBBCCCCBCB CCBBCCBCBCBBCCBBCCBCCCBCBCBBBCBCBCBBCCBC...
result:
ok good plan!
Subtask #5:
score: 7
Accepted
Test #5:
score: 7
Accepted
time: 1ms
memory: 9820kb
input:
8
output:
CBCBBBBBCBBBBCCBBBBBBBBBBBBBBBBBCCBCCCCCBBCCBBBBCCCCCCCBCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBBBBCBBCBBCBBBBBBBBBBBBBBBCBBBBBBBBBBBBBBBB BCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBBCBBBBBCBBBBCCBBCBBCBBCBBBBBCBBCCBCCCCCBCCBCCBCCCCCCCCCCCCCCCCCBBCBBBBBCBBBBCCBBCBBCBBCBBBBBCBB CBCBBBBBCCBCCBCCBBBBBBBCBBBBBBBBCCCCCCCCCC...
result:
ok good plan!
Subtask #6:
score: 7
Accepted
Test #6:
score: 7
Accepted
time: 3ms
memory: 9860kb
input:
9
output:
CCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBBBBBBBBBCCBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBCCBCBBCCBBCBCCBBCCBCBBCCBBCBBCBBBBBBBBBBCCBBBBCBBBBBBBBBCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCBBCBCCBBBBBCBBBBBCBCBBBBBBCBBCBBBBBBBBBBCCBBBBCCBBCBCCBBBBBCBBBBBCBBBBCCBBBBCBB BBCCBCCBCCCCCBCCBCCBCBBCCCCCBCCBCCCCCCCCCBB...
result:
ok good plan!
Subtask #7:
score: 7
Accepted
Test #7:
score: 7
Accepted
time: 1ms
memory: 12268kb
input:
10
output:
CBCBBBBBCBBBBCCBBBBBBBBBBBBBBBBBCBBCBCCBBBCBBBBBBCCBCBBBCBBCBCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCCBCCCCCBCCCCBBCCCCCCCCCCCCCCCCCBBCBBBBBCCBBCCCCBBBBBBBCBBBBBBBBCCCCCCCCCCCCCCCCCCCCCCCCCBCCBCCBCCCCCCCCCCCCCCCBCCCCCCCCCCCCCCCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
result:
ok good plan!
Subtask #8:
score: 7
Accepted
Test #8:
score: 7
Accepted
time: 6ms
memory: 8308kb
input:
11
output:
CCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBBBBBBBBBCCBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBCCBCBBCCBBCBCCBBBBBBBBBBBBBBCBBCBBCBBBBBBBBBBBCBBBBBBBBBCCBBBBBBBBBBBBBBBBBBBBBBCCBCBBCCBBCBBCBBBBBBCCBBCCBCBBBBCBBBBBCCBBBBCBBCBBCBBBBBBBBBBBCBBBBBCCBBCCBCBBBBCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBCCBCBBCCBBCBCCBBBBBBBBBBBBB...
result:
ok good plan!
Subtask #9:
score: 7
Accepted
Test #9:
score: 7
Accepted
time: 16ms
memory: 9992kb
input:
12
output:
CBCBBBBBCBBBBCCBBBBBBBBBBBBBBBBBCBBCBCCBBBCBBBBBBCCBCBBBCBBCBCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBBCBBBBBCBBBBCCBBBBBBBBBBBBBBBBBBCCBCBBCCBBCBCCBCBBCBCCBBBCBBBBBCBBCBCCBBCCBCBBBBCCBCBBCCBBCBCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
result:
ok good plan!
Subtask #10:
score: 7
Accepted
Test #10:
score: 7
Accepted
time: 48ms
memory: 14624kb
input:
13
output:
CCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBBBBBBBBBCCBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBCCBCBBCCBBCBCCBBBBBBBBBBBBBBCBBCBBCBBBBBBBBBBBCBBBBBBBBBCCBBBBBBBBBBBBBBBBBBBBBBCCBCBBCCBBCBBCBBBBBBCCBBCCBCBBBBCBBBBBCCBBBBCBBCBBCBBBBBCCBCBBCBBBBBCCBBBBBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBCCBCBBCCBBCBCCBBBBBBBBBBBBB...
result:
ok good plan!
Subtask #11:
score: 6
Accepted
Test #11:
score: 6
Accepted
time: 212ms
memory: 24212kb
input:
14
output:
CBCBBBBBCBBBBCCBBBBBBBBBBBBBBBBBCBBCBCCBBBCBBBBBBCCBCBBBCBBCBCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBCBBCBCCBBCCBCBBCBCCBCBBCCBBCBCCBBBCBBBBBCBBBBCCBBBBBBBBBBBBBBBBBBCCBCBBCCBBCBCCBCBBCBCCBBBCBBBBBCBBCBCCBBCCBCBBBBCCBCBBCCBBCBCCBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB...
result:
ok good plan!
Subtask #12:
score: 6
Accepted
Test #12:
score: 6
Accepted
time: 817ms
memory: 30264kb
input:
15
output:
CCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBBBBBBBBBCCBBBBBBCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBCCBCBBCCBBCBCCBBBBBBBBBBBBBBCBBCBBCBBBBBBBBBBBCBBBBBBBBBCCBBBBBBBBBBBBBBBBBBBBBBCCBCBBCCBBCBBCBBBBBBCCBBCCBCBBBBCBBBBBCCBBBBCBBCBBCBBBBBBBBBBBCBBBBBCCBBCCBCBBBBCBBCBBCBBBBBCBBCBBCBCCBBBBBCBBCBCCBCBBCCBBCBCCBBBBBBBBBBBBB...
result:
ok good plan!
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
Runtime Error
Test #15:
score: 0
Runtime Error
input:
18