結果
問題 | No.2967 Nana's Plus Permutation Game |
ユーザー |
|
提出日時 | 2024-11-16 20:32:59 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 504 ms / 2,000 ms |
コード長 | 958 bytes |
コンパイル時間 | 2,084 ms |
コンパイル使用メモリ | 197,504 KB |
最終ジャッジ日時 | 2025-02-25 04:57:36 |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 65 |
ソースコード
#include <bits/stdc++.h>using namespace std;using ll = long long;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), ans(n, -1);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++){rec(rec, i);if(dp[i] > mx){mx = dp[i];p = i;}}ans[p] = 1;for(int i = 2, v = p; i <= n; i++){v = ask(v, p);ans[v] = i;}cout << "2";for(int i = 0; i < n; i++){cout << ' ' << ans[i];}cout << endl;}