結果

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

ソースコード

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;
      });
      while (v.back() == v.size() - 1) v.pop_back();
      {
        int id = -1, len = v.size();
        for (int i = 0; i < len; ++i)
          if (v[i] == 0) id = i;
        bool ch = 1;
        for (int i = 0; i < len; ++i)
          if (v[(i + id) % len] != i) ch = 0;
        if (ch) return 1;
      }
    }
  }
  return 2;
}
0