結果

問題 No.2967 Nana's Plus Permutation Game
ユーザー kenken714
提出日時 2025-03-07 02:00:01
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 530 ms / 2,000 ms
コード長 1,196 bytes
コンパイル時間 2,220 ms
コンパイル使用メモリ 196,620 KB
実行使用メモリ 26,356 KB
平均クエリ数 4170.09
最終ジャッジ日時 2025-03-07 02:00:28
合計ジャッジ時間 25,447 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1
other AC * 65
権限があれば一括ダウンロードができます

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)
#define REPO(i, n) for (ll i = 1; i <= n; i++)
#define ll long long
#define INF (ll)1ll << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(), n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

vector<ll> g(5010, -1);
ll in[5010], n;

ll dfs(ll x, ll c){
  if(g[x] == -1) return c;
  return dfs(g[x], c + 1);
}

int main(){
  cin >> n;
  vector<ll> ans(n);
  REP(i, n){
    cout << 1 <<" " << i + 1 <<" " << i + 1 << endl;
    ll res;
    cin >> res;
    if(res != -1){
      res--;
      in[res]++;
      g[i] = res;
    }
  }
  ll best = 0, one = 0;
  REP(i, n){
    if(in[i] == 0){
      ll res = dfs(i, 0);
      if(best < res){
        best = res;
        one = i;
      }
    }
  }
  ll now = one;
  ans[now] = 1;
  FOR(i, 2, n + 1){
    cout << 1 << " " << one + 1 <<" " << now + 1 << endl;
    ll res;
    cin >> res;
    res--;
    now = res;
    ans[now] = i;
  }
  cout << 2;
  REP(i, n){
    cout << " " << ans[i];
  }
  cout << endl;
}
0