結果

問題 No.3489 あみだくじ作り
コンテスト
ユーザー yamate11
提出日時 2026-04-03 21:36:25
言語 C++23
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,193 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 3,174 ms
コンパイル使用メモリ 336,588 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-03 21:36:40
合計ジャッジ時間 3,197 ms
ジャッジサーバーID
(参考情報)
judge2_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 20
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
#include <cassert>
using namespace std;
using ll = long long int;
using u64 = unsigned long long;
using pll = pair<ll, ll>;
// #include <atcoder/all>
// using namespace atcoder;
#define REP(i, a, b) for (ll i = (a); i < (b); i++)
#define REPrev(i, a, b) for (ll i = (a); i >= (b); i--)
#define ALL(coll) (coll).begin(), (coll).end()
#define SIZE(v) ((ll)((v).size()))
#define REPOUT(i, a, b, exp, sep) REP(i, (a), (b)) cout << (exp) << (i + 1 == (b) ? "" : (sep)); cout << "\n"

// @@ !! LIM()

int main(/* int argc, char *argv[] */) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);

  ll N; cin >> N;
  // @InpVec(N, P, dec=1) [YWulLHjw]
  auto P = vector(N, ll());
  for (int i = 0; i < N; i++) { ll v; cin >> v; v -= 1; P[i] = v; }
  // @End [YWulLHjw]
  vector A(N, 0LL);
  REP(i, 0, N) A[P[i]] = i;
  vector<ll> ans;
  REP(i, 0, N) {
    REP(j, 0, N - 1) {
      if (A[j] > A[j + 1]) {
        ans.push_back(j);
        swap(A[j], A[j + 1]);
      }
    }
  }
  ranges::reverse(ans);
  cout << "Yes\n";
  cout << ssize(ans) << endl;
  if (ssize(ans) > 0) {
    REPOUT(i, 0, ssize(ans), ans[i] + 1, "\n");
  }


  return 0;
}

0