結果
| 問題 | 
                            No.1425 Yet Another Cyclic Shifts Sorting
                             | 
                    
| コンテスト | |
| ユーザー | 
                             sapphire__15
                         | 
                    
| 提出日時 | 2021-03-18 05:39:14 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 85 ms / 2,000 ms | 
| コード長 | 2,293 bytes | 
| コンパイル時間 | 1,063 ms | 
| コンパイル使用メモリ | 123,324 KB | 
| 最終ジャッジ日時 | 2025-01-19 18:02:02 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 48 | 
コンパイルメッセージ
main.cpp: In function ‘bool is_cyc(std::vector<int>&)’:
main.cpp:88:41: warning: ‘vl’ may be used uninitialized [-Wmaybe-uninitialized]
   88 |         return *min_element(all(da)) == vl;
      |                                         ^~
main.cpp:77:18: note: ‘vl’ was declared here
   77 |     int cnt = 0, vl;
      |                  ^~
            
            ソースコード
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>
#include <iomanip>
#include <limits>
#include <random>
#include <unordered_map>
typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;
#define rip(_i, _n, _s) for (int _i = (_s); _i < (int)(_n); _i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<
template<typename _T>
using MaxHeap = std::priority_queue<_T>;
template<typename _T>
using MinHeap = std::priority_queue<_T, std::vector<_T>, std::greater<_T>>;
template<typename _T>
inline bool chmax(_T &_l, const _T _b) {
    if (_l < _b) {
        _l = _b;
        return true;
    }
    return false;
}
template<typename _T>
inline bool chmin(_T &_l, const _T _b) {
    if (_l > _b) {
        _l = _b;
        return true;
    }
    return false;
}
template<typename _T>
void vdeb(const std::vector<_T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename _T>
void vdeb(const std::vector<std::vector<_T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}
using namespace std;
bool is_sorted(vector<int> &da) {
    rip(i, da.size()-1, 0) {
        if(da[i] > da[i+1]) return false;
    }
    return true;
}
bool is_cyc(vector<int> &da) {
    int cnt = 0, vl;
    rip(i,da.size()-1,0) {
        if(da[i] > da[i+1]) {
            cnt++;
            vl = da[i+1];
            if(cnt == 2) {
                return false;
            }
        }
    }
    if(*max_element(all(da)) == da.back()) {
        return *min_element(all(da)) == vl;
    }
    else {
        return da[0] >= da.back();
    }
}
int main() {
    int n; cin >> n;
    vector<int> da(n);
    rip(i,n,0) cin >> da[i];
    if(is_sorted(da)) {
        cout << 0 << endl;
    }
    else if(is_cyc(da)) {
        cout << 1 << endl;
    }
    else {
        cout << 2 << endl;
    }
}
            
            
            
        
            
sapphire__15