結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー m_tsubasa
提出日時 2021-03-12 22:25:51
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,303 bytes
コンパイル時間 1,797 ms
コンパイル使用メモリ 197,508 KB
最終ジャッジ日時 2025-01-19 15:08:01
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 42 WA * 6
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int n;
vector<int> a;

int solve();

int main() {
  cin >> n;
  a.resize(n);
  for (auto &p : a) cin >> p;
  cout << solve() << endl;
  return 0;
}

int solve() {
  {  // 0
    bool ch = 1;
    for (int i = 1; i < n; ++i)
      if (a[i - 1] > a[i]) ch = 0;
    if (ch) return 0;
  }
  {  // 1
    {
      vector<int> v(n);
      iota(v.begin(), v.end(), 0);
      sort(v.begin(), v.end(), [](int l, int r) {
        if (a[l] != a[r]) return a[l] < a[r];
        return l < r;
      });
      int cnt = 0;
      for (int i = 1; i < n; ++i)
        if (v[i - 1] > v[i]) ++cnt;
      if (cnt == 1) return 1;
    }
    // int id = 0;
    // for (int i = 0; i < n; ++i)
    //   if (a[id] > a[i]) id = i;
    // if (id) {
    //   int last = a[id - 1], lid = id - 1;
    //   for (int i = id + 1; i < n; ++i)
    //     if (last <= a[i]) {
    //       lid = i;
    //       break;
    //     }
    //   bool ch = 1;
    //   if (id - 1 != lid) {
    //     for (int i = lid + 1; i < n; ++i)
    //       if (a[i - 1] > a[i]) ch = 0;
    //   }
    //   int len = (id - 1 == lid ? n : lid);
    //   for (int i = 1; i < len; ++i)
    //     if (a[(id + i - 1 + len) % len] > a[(id + i + len) % len]) ch = 0;
    //   if (ch) return 1;
    // }
  }
  return 2;
}
0