結果
| 問題 |
No.1425 Yet Another Cyclic Shifts Sorting
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-03-12 23:16:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 49 ms / 2,000 ms |
| コード長 | 684 bytes |
| コンパイル時間 | 5,289 ms |
| コンパイル使用メモリ | 254,980 KB |
| 最終ジャッジ日時 | 2025-01-19 15:44:19 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 48 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:15:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
15 | scanf("%d",&N);
| ~~~~~^~~~~~~~~
main.cpp:18:25: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
18 | rep(i,N){ int a; scanf("%d",&a); A[i]=a; Q[i]={a,i}; }
| ~~~~~^~~~~~~~~
ソースコード
#include <atcoder/all>
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using ull=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)
using mll=atcoder::static_modint<1000000007>;
int N;
vector<int> A;
vector<pair<int,int>> Q;
vector<int> P;
int main(){
scanf("%d",&N);
A.resize(N);
Q.resize(N);
rep(i,N){ int a; scanf("%d",&a); A[i]=a; Q[i]={a,i}; }
sort(Q.begin(),Q.end());
P.resize(N);
rep(i,N) P[i]=Q[i].second;
int xp=-1; rep(i,N) if(P[i]!=i) xp=i;
if(xp==-1){ printf("0\n"); return 0; }
int ans=1;
int cinv=0;
rep(i,xp) if(A[i]>A[i+1]) cinv++;
if(A[0]<A[xp]) cinv++;
if(cinv>1) ans=2;
printf("%d\n",ans);
return 0;
}
Nachia