結果
問題 | No.2967 Nana's Plus Permutation Game |
ユーザー | t98slider |
提出日時 | 2024-11-16 17:57:13 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,015 bytes |
コンパイル時間 | 2,872 ms |
コンパイル使用メモリ | 210,980 KB |
実行使用メモリ | 25,940 KB |
平均クエリ数 | 4170.58 |
最終ジャッジ日時 | 2024-11-16 17:57:43 |
合計ジャッジ時間 | 27,217 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | RE | - |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
testcase_10 | RE | - |
testcase_11 | RE | - |
testcase_12 | WA | - |
testcase_13 | WA | - |
testcase_14 | RE | - |
testcase_15 | RE | - |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | RE | - |
testcase_20 | RE | - |
testcase_21 | WA | - |
testcase_22 | RE | - |
testcase_23 | WA | - |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | WA | - |
testcase_27 | WA | - |
testcase_28 | WA | - |
testcase_29 | RE | - |
testcase_30 | WA | - |
testcase_31 | WA | - |
testcase_32 | WA | - |
testcase_33 | WA | - |
testcase_34 | RE | - |
testcase_35 | WA | - |
testcase_36 | WA | - |
testcase_37 | RE | - |
testcase_38 | WA | - |
testcase_39 | RE | - |
testcase_40 | RE | - |
testcase_41 | WA | - |
testcase_42 | WA | - |
testcase_43 | RE | - |
testcase_44 | RE | - |
testcase_45 | RE | - |
testcase_46 | WA | - |
testcase_47 | WA | - |
testcase_48 | RE | - |
testcase_49 | RE | - |
testcase_50 | RE | - |
testcase_51 | RE | - |
testcase_52 | RE | - |
testcase_53 | WA | - |
testcase_54 | WA | - |
testcase_55 | WA | - |
testcase_56 | RE | - |
testcase_57 | WA | - |
testcase_58 | WA | - |
testcase_59 | WA | - |
testcase_60 | WA | - |
testcase_61 | AC | 64 ms
25,196 KB |
testcase_62 | AC | 65 ms
24,556 KB |
testcase_63 | AC | 67 ms
24,556 KB |
testcase_64 | RE | - |
testcase_65 | WA | - |
ソースコード
#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; }