結果

問題 No.2967 Nana's Plus Permutation Game
ユーザー t98slider
提出日時 2024-11-16 17:57:13
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 4,015 bytes
コンパイル時間 2,434 ms
コンパイル使用メモリ 205,216 KB
最終ジャッジ日時 2025-02-25 04:52:06
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 1
other AC * 4 WA * 41 RE * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
プレゼンテーションモードにする

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
unsigned long long xor64() {
static unsigned long long x
= (unsigned long long)(chrono::duration_cast<chrono::nanoseconds>(
chrono::high_resolution_clock::now().time_since_epoch()).count())
* 10150724397891781847ULL;
x ^= x << 7;
return x ^= x >> 9;
}
struct Weighted_dsu {
public:
Weighted_dsu() : _n(0) {}
Weighted_dsu(int n) : _n(n), num_component(n), parent_or_size(n, -1), diff_weight(n) {}
bool merge(int a, int b, long long w) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
int x = leader(a), y = leader(b);
w += diff_weight[a] - diff_weight[b];
if(x == y) return w == 0;
if (-parent_or_size[x] < -parent_or_size[y]) std::swap(x, y), w *= -1;
parent_or_size[x] += parent_or_size[y];
parent_or_size[y] = x;
diff_weight[y] = w;
num_component--;
return true;
}
long long diff(int a, int b) {
assert(same(a, b));
return diff_weight[b] - diff_weight[a];
}
bool same(int a, int b) {
assert(0 <= a && a < _n);
assert(0 <= b && b < _n);
return leader(a) == leader(b);
}
int leader(int a) {
assert(0 <= a && a < _n);
if (parent_or_size[a] < 0) return a;
int r = leader(parent_or_size[a]);
diff_weight[a] += diff_weight[parent_or_size[a]];
return parent_or_size[a] = r;
}
int size() {
return num_component;
}
int size(int a) {
assert(0 <= a && a < _n);
return -parent_or_size[leader(a)];
}
std::vector<std::vector<int>> groups() {
std::vector<int> leader_buf(_n), group_size(_n);
for (int i = 0; i < _n; i++) {
leader_buf[i] = leader(i);
group_size[leader_buf[i]]++;
}
std::vector<std::vector<int>> result(_n);
for (int i = 0; i < _n; i++) {
result[i].reserve(group_size[i]);
}
for (int i = 0; i < _n; i++) {
result[leader_buf[i]].push_back(i);
}
result.erase(
std::remove_if(result.begin(), result.end(),
[&](const std::vector<int>& v) { return v.empty(); }),
result.end());
return result;
}
private:
int _n, num_component;
std::vector<int> parent_or_size;
std::vector<long long> diff_weight;
};
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) {
if(vec.empty()) return os;
os << vec[0];
for(auto it = vec.begin(); ++it != vec.end(); ) os << ' ' << *it;
return os;
}
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin >> n;
Weighted_dsu uf(n);
if(n == 2){
cout << "1 1 1" << endl;
int res;
cin >> res;
if(res == -1){
cout << "2 2 1" << endl;
}else{
cout << "2 1 2" << endl;
}
return 0;
}
int Q = 2 * n;
auto ask = [&](int i, int j){
if(Q == 0) return -1;
Q--;
int res;
cout << "1 " << i + 1 << " " << j + 1 << endl;
cin >> res;
return res == -1 ? -1 : res - 1;
};
int p = xor64() % n, p2 = -1;
vector<int> a(n), b(n);
int cnt = 0;
for(int i = 0; i < n; i++){
a[i] = ask(p, i);
if (a[i] != -1) cnt++;
}
a[p] = n - cnt;
for(int i = 0; i < n; i++){
if(a[i] == -1) continue;
uf.merge(i, a[i], a[p]);
if (i != p) p2 = i;
}
assert(p2 != -1);
cnt = 0;
for(int i = 0; i < n; i++){
b[i] = ask(p2, i);
if(b[i] != -1) cnt++;
}
a[p2] = n - cnt;
for(int i = 0; i < n; i++){
if(b[i] == -1) continue;
uf.merge(i, b[i], a[p2]);
}
for(int i = 0; i < n; i++){
if(i == p || i == p2) continue;
a[i] = uf.diff(a[p], i) + a[p];
}
cout << "2 " << a << endl;
}
הההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההההה
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
0