結果
問題 | No.2967 Nana's Plus Permutation Game |
ユーザー |
![]() |
提出日時 | 2024-11-16 17:44:14 |
言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 908 ms / 2,000 ms |
コード長 | 1,747 bytes |
コンパイル時間 | 3,132 ms |
コンパイル使用メモリ | 275,520 KB |
実行使用メモリ | 25,464 KB |
平均クエリ数 | 2638.47 |
最終ジャッジ日時 | 2024-11-16 17:44:49 |
合計ジャッジ時間 | 29,316 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 65 |
ソースコード
#include<bits/stdc++.h>namespace {#pragma GCC diagnostic ignored "-Wunused-function"#include<atcoder/all>#pragma GCC diagnostic warning "-Wunused-function"using namespace std;using namespace atcoder;#define rep(i,n) for(int i = 0; i < (int)(n); i++)#define rrep(i,n) for(int i = (int)(n) - 1; i >= 0; i--)#define all(x) begin(x), end(x)#define rall(x) rbegin(x), rend(x)template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }template<class T> bool chmin(T& a, const T& b) { if (b < a) { a = b; return true; } else return false; }using ll = long long;using P = pair<int,int>;using VI = vector<int>;using VVI = vector<VI>;using VL = vector<ll>;using VVL = vector<VL>;int ask(int i, int j) {cout << 1 << ' ' << i + 1 << ' ' << j + 1 << endl;int res;cin >> res;if (res != -1) res--;return res;}} int main() {ios::sync_with_stdio(false);cin.tie(0);int n;cin >> n;dsu uf(n);VI idx(n, 1);rep(i, n) {while (true) {if (idx[i] != 1) break;vector<int> seen(n + 1, -1);rep(j, n) if (uf.same(i, j)) seen[idx[j]] = j;bool end = true;for (int c1 = 2; c1 <= n; c1++) {if (seen[c1] == -1) {int res = ask(i, seen[c1-1]);if (res == -1) break;int c2 = idx[res];int g = gcd(c1, c2);int m1 = c2 / g, m2 = c1 / g;rep(j, n) {if (uf.same(i, j)) idx[j] *= m1;else if (uf.same(res, j)) idx[j] *= m2;}uf.merge(i, res);end = false;break;}}if (end) break;}}assert(uf.size(0) == n);cout << 2;for (int i : idx) cout << ' ' << i;cout << endl;}