結果
| 問題 |
No.366 ロボットソート
|
| コンテスト | |
| ユーザー |
femto
|
| 提出日時 | 2016-08-21 20:46:39 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 4 ms / 2,000 ms |
| コード長 | 634 bytes |
| コンパイル時間 | 1,056 ms |
| コンパイル使用メモリ | 84,692 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-29 18:30:45 |
| 合計ジャッジ時間 | 1,852 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int N, K;
cin >> N >> K;
vector<int> a(N);
for(int i = 0; i < N; i++) {
cin >> a[i];
}
int ans = 0;
for(int i = 0; i < N; i++) {
for(int j = i % K; j < N; j += K) {
if(j + K < N && a[j] > a[j + K]) {
swap(a[j], a[j + K]);
ans++;
}
}
}
for(int i = 0; i < N - 1; i++) {
if(a[i] > a[i + 1]) {
cout << -1 << endl;
return 0;
}
}
cout << ans << endl;
}
femto