結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー milanis48663220milanis48663220
提出日時 2021-03-12 22:10:24
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 139 ms / 2,000 ms
コード長 1,495 bytes
コンパイル時間 1,250 ms
コンパイル使用メモリ 98,276 KB
実行使用メモリ 13,440 KB
最終ジャッジ日時 2024-04-22 17:08:49
合計ジャッジ時間 4,588 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 1 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 66 ms
11,136 KB
testcase_23 AC 16 ms
5,504 KB
testcase_24 AC 13 ms
5,376 KB
testcase_25 AC 71 ms
11,520 KB
testcase_26 AC 83 ms
13,056 KB
testcase_27 AC 82 ms
11,776 KB
testcase_28 AC 89 ms
13,184 KB
testcase_29 AC 23 ms
6,200 KB
testcase_30 AC 17 ms
5,628 KB
testcase_31 AC 86 ms
13,056 KB
testcase_32 AC 26 ms
6,220 KB
testcase_33 AC 4 ms
5,376 KB
testcase_34 AC 29 ms
6,520 KB
testcase_35 AC 80 ms
12,544 KB
testcase_36 AC 76 ms
9,984 KB
testcase_37 AC 13 ms
5,376 KB
testcase_38 AC 133 ms
13,312 KB
testcase_39 AC 4 ms
5,376 KB
testcase_40 AC 96 ms
11,264 KB
testcase_41 AC 28 ms
6,416 KB
testcase_42 AC 36 ms
7,120 KB
testcase_43 AC 5 ms
5,376 KB
testcase_44 AC 12 ms
5,376 KB
testcase_45 AC 138 ms
13,440 KB
testcase_46 AC 136 ms
13,312 KB
testcase_47 AC 139 ms
13,440 KB
testcase_48 AC 130 ms
13,440 KB
testcase_49 AC 138 ms
13,440 KB
testcase_50 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define debug_value(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << #x << "=" << x << endl;
#define debug(x) cerr << "line" << __LINE__ << ":<" << __func__ << ">:" << x << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int n; cin >> n;
    vector<int> a(n);
    multiset<int> st;
    bool ok = true;
    for(int i = 0; i < n; i++) {
        cin >> a[i];
        st.insert(a[i]);
        if(i >= 1 && a[i] < a[i-1]) ok = false;
    }
    if(ok){
        cout << 0 << endl;
        return 0;
    }
    int r = -1;
    for(int i = n-1; i >= 1; i--){
        st.erase(st.find(a[i]));
        auto p = st.end();
        p--;
        if(*p > a[i]){
            r = i+1;
            break;
        }
    }
    int x = -1;
    for(int i = 1; i < r; i++){
        if(a[i] < a[i-1]) {
            x = i;
            break;
        }
    }
    ok = true;
    for(int i = x; ;i = (i+1)%r){
        if((i+1)%r == x) break;
        if(a[i] > a[(i+1)%r]) ok = false;
    }
    if(ok){
        cout << 1 << endl;
    }else{
        cout << 2 << endl;
    }
}
0