結果

問題 No.1425 Yet Another Cyclic Shifts Sorting
ユーザー hir355hir355
提出日時 2021-03-12 22:32:04
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 70 ms / 2,000 ms
コード長 2,721 bytes
コンパイル時間 2,617 ms
コンパイル使用メモリ 207,016 KB
実行使用メモリ 8,320 KB
最終ジャッジ日時 2024-04-22 17:12:54
合計ジャッジ時間 5,326 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
testcase_21 AC 2 ms
5,376 KB
testcase_22 AC 21 ms
5,376 KB
testcase_23 AC 7 ms
5,376 KB
testcase_24 AC 6 ms
5,376 KB
testcase_25 AC 23 ms
5,376 KB
testcase_26 AC 26 ms
5,376 KB
testcase_27 AC 32 ms
8,192 KB
testcase_28 AC 46 ms
8,192 KB
testcase_29 AC 12 ms
5,376 KB
testcase_30 AC 11 ms
5,376 KB
testcase_31 AC 48 ms
8,320 KB
testcase_32 AC 11 ms
5,376 KB
testcase_33 AC 3 ms
5,376 KB
testcase_34 AC 14 ms
5,760 KB
testcase_35 AC 43 ms
8,192 KB
testcase_36 AC 49 ms
7,808 KB
testcase_37 AC 10 ms
5,376 KB
testcase_38 AC 69 ms
8,320 KB
testcase_39 AC 3 ms
5,376 KB
testcase_40 AC 57 ms
8,192 KB
testcase_41 AC 21 ms
5,376 KB
testcase_42 AC 27 ms
5,632 KB
testcase_43 AC 5 ms
5,376 KB
testcase_44 AC 10 ms
5,376 KB
testcase_45 AC 69 ms
8,320 KB
testcase_46 AC 69 ms
8,064 KB
testcase_47 AC 70 ms
8,064 KB
testcase_48 AC 70 ms
8,192 KB
testcase_49 AC 70 ms
8,192 KB
testcase_50 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <atcoder/segtree>
#include <bits/stdc++.h>
using namespace std;
using namespace atcoder;
const long long INF_LL = 2000000000000000000LL;
const int INF = 2000000000;
const long long MOD = 1000000007;
#define ll long long
#define all(x) x.begin(), x.end()
#define REP(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) REP(i, 0, n)
// typedef float double;
// typedef priority_queue prique;
typedef pair<ll, ll> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<ll> vl;
typedef vector<vi> matrix;
int dx[4] = {0, -1, 0, 1};
int dy[4] = {1, 0, -1, 0};
int sign[2] = {1, -1};
template <class T> bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}

ll modpow(ll a, ll b, ll m) {
    if(b == 0)
        return 1;
    ll t = modpow(a, b / 2, m);
    if(b & 1) {
        return (t * t % m) * a % m;
    } else {
        return t * t % m;
    }
}

struct edge {
    int to;
    ll cost;
    edge(int t, ll c) { to = t, cost = c; }
};

typedef vector<vector<edge>> graph;

// using mint = modint998244353;

vector<long long> prime_factorize(long long N) {
    vector<long long> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        while (N % a == 0) {
            N /= a;
        }
        res.push_back(a);
    }
    if (N != 1) res.push_back(N);
    return res;
}

int op1(int a, int b){
    return max(a, b);
}

int op2(int a, int b){
    return min(a, b);
}

bool op3(bool a, bool b){
    return a & b;
}

int e1(){return 0;}

int e2(){return INF;}

bool e3(){return true;}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    int n;
    cin >> n;
    vi a(n);
    rep(i, n) cin >> a[i];
    bool flg = true;
    rep(i, n - 1){
        if(a[i] > a[i + 1]){
            flg = false;
        }
    }
    if(flg){
        cout << 0 << endl;
        return 0;
    }
    segtree<int, op1, e1> maxseg(a);
    segtree<int, op2, e2> minseg(a);
    segtree<bool, op3, e3> andseg(n - 1);
    rep(i, n - 1){
        if(a[i] > a[i + 1]) andseg.set(i, false);
    }
    REP(i, 1, n){
        if(!andseg.prod(i, n - 1) || !andseg.prod(0, i - 1)){
            continue;
        }
        int l = i, r = n + 1;
        while(r - l > 1){
            int m = (l + r) / 2;
            if(maxseg.prod(i, m) <= minseg.prod(0, i - 1)){
                l = m;
            }else{
                r = m;
            }
        }
        if(maxseg.prod(0, i) <= minseg.prod(l, n)){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 2 << endl;
    return 0;
}
0