結果
| 問題 | No.3766 PQ Disjunction |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-10-16 22:54:16 |
| 言語 | C++23 (gcc 15.3.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 26 ms / 1,000 ms |
| + 509µs | |
| コード長 | 2,256 bytes |
| 記録 | |
| コンパイル時間 | 2,747 ms |
| コンパイル使用メモリ | 339,952 KB |
| 実行使用メモリ | 9,848 KB |
| 最終ジャッジ日時 | 2026-10-16 22:54:29 |
| 合計ジャッジ時間 | 7,089 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge3_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 34 |
ソースコード
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,s,n) for (int i = (s); i < (n); ++i)
#define rrep(i,g,n) for (int i = (n)-1; i >= (g); --i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define len(x) (int)(x).size()
#define dup(x,y) (((x)+(y)-1)/(y))
#define pb push_back
#define eb emplace_back
#define Field(T) vector<vector<T>>
using namespace std;
using ll = long long;
using ull = unsigned long long;
template<typename T> using pq = priority_queue<T,vector<T>,greater<T>>;
using P = pair<int,int>;
template<class T>bool chmax(T&a,T b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T&a,T b){if(b<a){a=b;return 1;}return 0;}
int main() {
int n, k;
cin >> n >> k;
if (__builtin_popcount(n) == 1) {
if (k >= n) {
cout << "No" << endl;
} else {
vector<int> p(n);
rep(i,0,n) p[i] = n-i-1;
swap(p[n-1], p[n-k-1]);
cout << "Yes" << endl;
rep(i,0,n) cout << i << " ";
cout << endl;
rep(i,0,n) cout << p[i] << " ";
cout << endl;
return 0;
}
return 0;
}
int l = 31-__builtin_clz(n);
if (k >= (1<<(l+1))) {
cout << "No" << endl;
return 0;
}
function<int(vector<int>)> g = [&](vector<int> p) {
int ret = 0;
rep(i,0,n) ret |= (i&p[i]);
return ret;
};
function<vector<int>(int)> f = [&](int x) {
int b = 31-__builtin_clz(x);
vector<int> ret(1<<b);
iota(all(ret), 0), reverse(all(ret));
if (x != (1<<b)) {
vector<int> y = f(x-(1<<b));
rep(i,0,x-(1<<b)) ret[(1<<b)-i-1] += (1<<b);
for (int e : y) ret.eb(e);
}
return ret;
};
vector<int> p = f(n);
swap(p[(1<<l)-1], p[(1<<l)-1-(k%(1<<l))]);
if (k >= (1<<l)) {
int p1 = -1, p2 = -1;
rep(i,0,n) {
if (p[i] == 0) p1 = i;
if (p[i] == (1<<l)) p2 = i;
}
swap(p[p1], p[p2]);
}
cout << "Yes" << endl;
rep(i,0,n) cout << i << " ";
cout << endl;
for (int e : p) cout << e << " ";
cout << endl;
// cout << g(p) << endl;
// vector<int> p(n);
// iota(all(p), 0);
// do {
// int x = 0;
// rep(i,0,n) x |= (i&p[i]);
// for (auto e : p) cout << e << " ";
// cout << "-> " << x << endl;
// } while(next_permutation(all(p)));
return 0;
}