結果
問題 | No.366 ロボットソート |
ユーザー |
|
提出日時 | 2016-04-29 22:45:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 816 bytes |
コンパイル時間 | 778 ms |
コンパイル使用メモリ | 75,820 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 17:40:29 |
合計ジャッジ時間 | 1,666 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <iostream>#include <algorithm>#include <vector>using ll = long long int;int main(){std::ios::sync_with_stdio(false);std::cin.tie(0);int n, k;std::cin >> n >> k;std::vector<int> a(n);for(auto& i : a){std::cin >> i;}std::vector<int> aBase(a);std::sort(aBase.begin(), aBase.end());int count = 0;for(int i=0; i<k; ++i){bool flag;do{flag = false;for(int j=i; j<n-k; j+=k){if(a[j]>a[j+k]){++count;flag=true;std::swap(a[j], a[j+k]);}}}while(flag);}if(aBase == a){std::cout << count << "\n";}else{std::cout << -1 << "\n";}return 0;}