Submission #64621
ソースコード
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 | #include <iostream> #include <vector> #include <algorithm> #include <numeric> using namespace std; int main(){ int n; cin >> n; vector< int > a(n); for ( int i = 0; i < n; ++i){ cin >> a[i]; } auto sorted = a; sort(sorted.begin(), sorted.end()); vector< int > pos(n+1), dist(n+1); for ( int i = 0; i < n; ++i){ pos[sorted[i]] = i; } for ( int i = 0; i < n; ++i){ dist[a[i]] = abs (i - pos[a[i]]); } int res = accumulate(dist.begin(), dist.end(), 0, []( int a, int b){ return (gcd(a, b)); }); if (res == 0){ cout << n - 1 << '\n' ; } else { cout << res << '\n' ; } return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 1419 - Permutation Sort |
ユーザー名 | ei1903 |
投稿日時 | 2020-11-05 17:58:42 |
言語 | C++17 |
状態 | Accepted |
得点 | 4 |
ソースコード長 | 720 Byte |
最大実行時間 | 160 ms |
最大メモリ使用量 | 8588 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 4 / 4 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 101 ms | 6108 KB |
1
|
in02.txt | AC | 84 ms | 3956 KB |
1
|
in03.txt | AC | 111 ms | 6132 KB |
1
|
in04.txt | AC | 99 ms | 4744 KB |
1
|
in05.txt | AC | 132 ms | 8240 KB |
1
|
in06.txt | AC | 138 ms | 8324 KB |
1
|
in07.txt | AC | 158 ms | 8280 KB |
1
|
in08.txt | AC | 151 ms | 8364 KB |
1
|
in09.txt | AC | 154 ms | 8448 KB |
1
|
in10.txt | AC | 151 ms | 8404 KB |
1
|
in11.txt | AC | 126 ms | 8356 KB |
1
|
in12.txt | AC | 127 ms | 8440 KB |
1
|
in13.txt | AC | 127 ms | 8396 KB |
1
|
in14.txt | AC | 154 ms | 8220 KB |
1
|
in15.txt | AC | 153 ms | 8304 KB |
1
|
in16.txt | AC | 160 ms | 8388 KB |
1
|
in17.txt | AC | 153 ms | 8340 KB |
1
|
in18.txt | AC | 156 ms | 8296 KB |
1
|
in19.txt | AC | 20 ms | 568 KB |
1
|
in20.txt | AC | 21 ms | 664 KB |
1
|
in21.txt | AC | 23 ms | 636 KB |
1
|
in22.txt | AC | 125 ms | 8420 KB |
1
|
in23.txt | AC | 123 ms | 8252 KB |
1
|
in24.txt | AC | 119 ms | 8588 KB |
1
|
in25.txt | AC | 129 ms | 8544 KB |
1
|
in26.txt | AC | 124 ms | 8376 KB |
1
|
in27.txt | AC | 126 ms | 8460 KB |
1
|
in28.txt | AC | 130 ms | 8548 KB |
1
|
in29.txt | AC | 137 ms | 8500 KB |
1
|
in30.txt | AC | 127 ms | 8588 KB |
1
|
sample01.txt | AC | 21 ms | 608 KB |
1
|
sample02.txt | AC | 20 ms | 712 KB |
1
|