結果
| 問題 |
No.366 ロボットソート
|
| コンテスト | |
| ユーザー |
iqueue02
|
| 提出日時 | 2020-07-28 15:16:06 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 5 ms / 2,000 ms |
| コード長 | 624 bytes |
| コンパイル時間 | 3,052 ms |
| コンパイル使用メモリ | 204,140 KB |
| 最終ジャッジ日時 | 2025-01-12 07:14:52 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n);i++)
#define sz(x) int(x.size())
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
int main() {
int n, k;
cin >> n >> k;
vector<int> a(n);
rep(i,n) cin >> a[i];
auto b = a;
sort(b.begin(), b.end());
map<int,int> id;
for (int i = 0; i < n; i++) id[b[i]] = i;
ll res = 0;
for (int i = 0; i < n; i++) {
if (id[a[i]] % k != i % k) {
cout << -1 << endl;
return 0;
}
for (int j = i; j >= 0; j -= k) if (a[j] > a[i]) res++;
}
cout << res << endl;
return 0;
}
iqueue02