結果
| 問題 |
No.1425 Yet Another Cyclic Shifts Sorting
|
| コンテスト | |
| ユーザー |
milanis48663220
|
| 提出日時 | 2021-03-12 22:10:24 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 257 ms / 2,000 ms |
| コード長 | 1,495 bytes |
| コンパイル時間 | 1,246 ms |
| コンパイル使用メモリ | 94,560 KB |
| 最終ジャッジ日時 | 2025-01-19 14:53:26 |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 |
ソースコード
#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;
}
}
milanis48663220