結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー snow39snow39
提出日時 2021-03-18 15:30:20
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 43 ms / 2,000 ms
コード長 973 bytes
コンパイル時間 1,327 ms
コンパイル使用メモリ 111,100 KB
実行使用メモリ 5,760 KB
最終ジャッジ日時 2024-04-28 05:49:07
合計ジャッジ時間 4,894 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 2 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 2 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 23 ms
5,376 KB
testcase_23 AC 8 ms
5,376 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 24 ms
5,376 KB
testcase_26 AC 29 ms
5,376 KB
testcase_27 AC 26 ms
5,376 KB
testcase_28 AC 36 ms
5,632 KB
testcase_29 AC 11 ms
5,376 KB
testcase_30 AC 10 ms
5,376 KB
testcase_31 AC 38 ms
5,504 KB
testcase_32 AC 10 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 AC 11 ms
5,376 KB
testcase_35 AC 37 ms
5,376 KB
testcase_36 AC 29 ms
5,376 KB
testcase_37 AC 7 ms
5,376 KB
testcase_38 AC 43 ms
5,504 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 35 ms
5,376 KB
testcase_41 AC 14 ms
5,376 KB
testcase_42 AC 17 ms
5,376 KB
testcase_43 AC 4 ms
5,376 KB
testcase_44 AC 7 ms
5,376 KB
testcase_45 AC 43 ms
5,632 KB
testcase_46 AC 43 ms
5,632 KB
testcase_47 AC 43 ms
5,504 KB
testcase_48 AC 43 ms
5,760 KB
testcase_49 AC 43 ms
5,632 KB
testcase_50 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;
const ll MOD=1e9+7;
template<class T> void chmin(T &a,const T &b){if(a>b) a=b;}
template<class T> void chmax(T &a,const T &b){if(a<b) a=b;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  int N;
  cin>>N;
  vector<int> A(N);
  rep(i,N) cin>>A[i];

  vector<int> B=A;
  sort(all(B));

  if(A==B){
    cout<<0<<endl;
    return 0;
  }

  vector<int> dp(N+1,0);
  dp[0]=0;
  for(int i=0;i+1<N;i++){
    dp[i+1]=dp[i];
    if(A[i]>A[i+1]) dp[i+1]++;
  }

  for(int i=N-1;i>=1;i--){
    if(dp[i]==1&&A[0]>=A[i]){
      cout<<1<<endl;
      return 0;
    }
    if(A[i]!=B[i]) break;
  }
  
  cout<<2<<endl;

  return 0;
}
0