結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー fumofumofunifumofumofuni
提出日時 2021-03-13 00:41:37
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 102 ms / 2,000 ms
コード長 1,492 bytes
コンパイル時間 2,277 ms
コンパイル使用メモリ 201,952 KB
実行使用メモリ 11,108 KB
最終ジャッジ日時 2024-04-22 17:19:40
合計ジャッジ時間 5,692 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,248 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 3 ms
5,376 KB
testcase_13 AC 2 ms
5,376 KB
testcase_14 AC 3 ms
5,376 KB
testcase_15 AC 3 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 3 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 69 ms
5,788 KB
testcase_23 AC 19 ms
5,376 KB
testcase_24 AC 16 ms
5,376 KB
testcase_25 AC 70 ms
6,100 KB
testcase_26 AC 81 ms
6,600 KB
testcase_27 AC 75 ms
9,864 KB
testcase_28 AC 91 ms
11,104 KB
testcase_29 AC 27 ms
5,524 KB
testcase_30 AC 22 ms
5,376 KB
testcase_31 AC 93 ms
10,824 KB
testcase_32 AC 26 ms
5,384 KB
testcase_33 AC 5 ms
5,376 KB
testcase_34 AC 28 ms
5,960 KB
testcase_35 AC 88 ms
10,468 KB
testcase_36 AC 67 ms
8,544 KB
testcase_37 AC 13 ms
5,376 KB
testcase_38 AC 100 ms
10,968 KB
testcase_39 AC 5 ms
5,376 KB
testcase_40 AC 79 ms
9,520 KB
testcase_41 AC 31 ms
5,572 KB
testcase_42 AC 38 ms
6,172 KB
testcase_43 AC 6 ms
5,376 KB
testcase_44 AC 14 ms
5,376 KB
testcase_45 AC 100 ms
10,980 KB
testcase_46 AC 101 ms
10,852 KB
testcase_47 AC 102 ms
11,108 KB
testcase_48 AC 96 ms
11,108 KB
testcase_49 AC 98 ms
10,980 KB
testcase_50 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=(n)-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
 ll MOD=1000000007;
 ll MOD9=998244353;
 int inf=1e9+10;
 ll INF=1e18;
 ll dy[8]={1,0,-1,0,1,1,-1,-1};
 ll dx[8]={0,1,0,-1,1,-1,1,-1};
template <typename T> inline bool chmax(T &a, T b) {
  return ((a < b) ? (a = b, true) : (false));
}
template <typename T> inline bool chmin(T &a, T b) {
  return ((a > b) ? (a = b, true) : (false));
}

int main(){
  ll n;cin >> n;
  vl v(n);rep(i,n)cin >> v[i];v.pb(INF);
  vl p=v;sort(all(p));
  if(p==v)cout << 0 <<endl,exit(0);
  vl cm=v;
  rep(i,n)chmax(cm[i+1],cm[i]);
  vl flag(n+1);flag[n]=true;
  per(i,n)flag[i]=flag[i+1]&(v[i]<=v[i+1]);
  vl lower(n);
  rep(i,n-1){
    lower[i+1]=lower[i]+(v[i]>v[i+1]);
  }
  //rep(i,n+1)cout << flag[i] <<" ";cout << endl;
  //rep(i,n)cout << lower[i] <<" ";cout << endl;
  for(int i=1;i<n;i++){
    if(flag[i+1]&&lower[i]<=1&&cm[i]<=v[i+1]&&v[i]<=v[0]){
      cout << 1 <<endl;return 0;
    }
  }
  cout  << 2 <<endl;
}
0