Submission #64693
ソースコード
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include<bits/stdc++.h> using namespace std; template < class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true ); } template < class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true ); } typedef long long ll; typedef vector< int > vint; typedef pair< int , int > pint; typedef vector< long long > vlong; typedef vector<string> vstring; #define _GLIBCXX_DEBUG #define vpush(a,x) a.push_back(x); #define rep(i, n) REP(i, 0, n) #define all(v) v.begin(), v.end() #define REP(i, x, n) for(int i = x; i < n; i++) const int INF = 1 << 30; const int dx[] = {1,0,-1,0,1,1,-1,-1}; const int dy[] = {0,-1,0,1,1,-1,-1,1}; #define stp(x) setprecision(x) int main(){ int n; cin>>n; vint a(n); vint where(n+5); rep(i,n){ cin>>a[i]; where[a[i]]=i+1; } int ans=n-1; bool fg= true ; REP(i,1,n+1){ if (i!=where[i]){ if (fg){ ans= abs (i-where[i]); } fg= false ; ans=gcd(ans, abs (i-where[i])); } } cout<<ans<< '\n' ; return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 1419 - Permutation Sort |
ユーザー名 | ei1918 |
投稿日時 | 2020-11-11 00:25:52 |
言語 | C++17 |
状態 | Accepted |
得点 | 4 |
ソースコード長 | 1050 Byte |
最大実行時間 | 132 ms |
最大メモリ使用量 | 4592 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 4 / 4 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 98 ms | 3420 KB |
1
|
in02.txt | AC | 64 ms | 2140 KB |
1
|
in03.txt | AC | 92 ms | 3220 KB |
1
|
in04.txt | AC | 101 ms | 2704 KB |
1
|
in05.txt | AC | 124 ms | 4436 KB |
1
|
in06.txt | AC | 123 ms | 4464 KB |
1
|
in07.txt | AC | 132 ms | 4496 KB |
1
|
in08.txt | AC | 129 ms | 4520 KB |
1
|
in09.txt | AC | 119 ms | 4544 KB |
1
|
in10.txt | AC | 124 ms | 4568 KB |
1
|
in11.txt | AC | 122 ms | 4592 KB |
1
|
in12.txt | AC | 118 ms | 4492 KB |
1
|
in13.txt | AC | 119 ms | 4520 KB |
1
|
in14.txt | AC | 126 ms | 4544 KB |
1
|
in15.txt | AC | 129 ms | 4312 KB |
1
|
in16.txt | AC | 120 ms | 4340 KB |
1
|
in17.txt | AC | 129 ms | 4496 KB |
1
|
in18.txt | AC | 123 ms | 4388 KB |
1
|
in19.txt | AC | 20 ms | 576 KB |
1
|
in20.txt | AC | 20 ms | 548 KB |
1
|
in21.txt | AC | 32 ms | 772 KB |
1
|
in22.txt | AC | 118 ms | 4456 KB |
1
|
in23.txt | AC | 119 ms | 4484 KB |
1
|
in24.txt | AC | 127 ms | 4384 KB |
1
|
in25.txt | AC | 118 ms | 4288 KB |
1
|
in26.txt | AC | 119 ms | 4576 KB |
1
|
in27.txt | AC | 119 ms | 4348 KB |
1
|
in28.txt | AC | 112 ms | 4496 KB |
1
|
in29.txt | AC | 113 ms | 4400 KB |
1
|
in30.txt | AC | 118 ms | 4428 KB |
1
|
sample01.txt | AC | 22 ms | 492 KB |
1
|
sample02.txt | AC | 22 ms | 596 KB |
1
|