結果
問題 | No.2967 Nana's Plus Permutation Game |
ユーザー |
|
提出日時 | 2024-11-16 20:44:55 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 438 ms / 2,000 ms |
コード長 | 1,055 bytes |
コンパイル時間 | 2,185 ms |
コンパイル使用メモリ | 195,732 KB |
最終ジャッジ日時 | 2025-02-25 04:58:02 |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 65 |
ソースコード
#include <bits/stdc++.h>using namespace std;int main(){ios::sync_with_stdio(false);cin.tie(0);int n;cin >> n;auto ask = [&](int u, int v){int res;cout << "1 " << u + 1 << " " << v + 1 << endl;cin >> res;return res == -1 ? -1 : res - 1;};vector<int> a(n);for(int i = 0; i < n; i++) a[i] = ask(i, i);vector<int> dp(n);auto rec = [&](auto rec, int v) -> int {if (dp[v] != 0) return dp[v];return dp[v] = 1 + (a[v] == -1 ? 0 : rec(rec, a[v]));};int p = -1, mx = -1;for(int i = 0; i < n; i++){if(rec(rec, i) > mx){mx = dp[i];p = i;}}vector<int> ans(n);for(int i = 1, v = p; i <= n; i += 2){if(i != 1) v = ask(v, a[p]);ans[v] = i;int v2 = a[v], c = i;while(v2 != -1){ans[v2] = (c += c);v2 = a[v2];}}cout << "2";for(int i = 0; i < n; i++){cout << ' ' << ans[i];}cout << endl;}