結果
| 問題 | No.3766 PQ Disjunction |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-16 21:55:50 |
| 言語 | C++17 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 30 ms / 1,000 ms |
| + 28µs | |
| コード長 | 2,110 bytes |
| 記録 | |
| コンパイル時間 | 1,424 ms |
| コンパイル使用メモリ | 220,416 KB |
| 実行使用メモリ | 9,920 KB |
| 最終ジャッジ日時 | 2026-10-16 21:56:07 |
| 合計ジャッジ時間 | 5,629 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,K; cin >> N >> K;
const int D = 18;
{
int all = 0;
for(int i=0; i<N; i++) all |= i;
if((all&K) != K){cout << "No\n"; return 0;}
}
auto f = [&](auto f,int n,int d=-1) -> vector<pair<int,int>> {
if(d == -1) while(true){
d++;
if(n <= (1<<d)) break;
}
while(d && n <= (1<<(d-1))) d--;
vector<pair<int,int>> ret;
if(n == (1<<d)){
for(int i=0; i<n; i++) ret.push_back({i,n-1-i});
return ret;
}
d--;
auto P1 = f(f,(1<<d),d),P2 = f(f,n-(1<<d),d);
int twice = n-(1<<d);
for(auto [a,b] : P1){
if(a < twice) ret.push_back({a+(1<<d),b});
else ret.push_back({a,b});
}
for(auto [a,b] : P2){
if(b < twice) ret.push_back({a,b+(1<<d)});
else ret.push_back({a,b});
}
return ret;
};
auto g = [&](auto g,int n,int d=-1) -> vector<pair<int,int>> {
assert(n > 0);
if(n == 1) return {{0,0}};
if(d == -1) while(true){
d++;
if(n <= (1<<d)) break;
}
d--;
int twice = n-(1<<d);
vector<pair<int,int>> ret;
if(K&(1<<d)){
auto P1 = g(g,(1<<d),d),P2 = f(f,twice,d);
for(auto [a,b] : P1) ret.push_back({a,b});
for(auto [a,b] : P2) ret.push_back({a+(1<<d),b+(1<<d)});
}
else{
auto P1 = g(g,(1<<d),d),P2 = f(f,twice,d);
for(auto [a,b] : P1){
if(a < twice) a += 1<<d;
ret.push_back({a,b});
}
for(auto [a,b] : P2){
if(b < twice) b += 1<<d;
ret.push_back({a,b});
}
}
return ret;
};
vector<pair<int,int>> answer = g(g,N);
cout << "Yes\n";
for(auto [x,y] : answer) cout << x << " "; cout << endl;
for(auto [x,y] : answer) cout << y << " "; cout << endl;
}