結果
| 問題 | No.366 ロボットソート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-10 16:47:37 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 908 bytes |
| 記録 | |
| コンパイル時間 | 2,048 ms |
| コンパイル使用メモリ | 219,672 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-02-10 16:47:41 |
| 合計ジャッジ時間 | 3,575 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 15 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
const int maxn = 1e5 + 1;
#define pii pair<int, int>
#define ll long long
#define pq priority_queue
#define se second
#define fi first
int n, k;
struct node{
int id, val;
};
vector<node> a;
void solve() {
cin >> n;
a.resize(n);
for (int i = 0; i < n; i++){
cin >> a[i].val;
a[i].id = i;
}
sort(a.begin(), a.end(), [](const node &x, const node &y) {
return x.val < y.val;
});
cin >> k;
bool ok = true;
int ans = 0;
for (int i = 0; i < n; i++) {
if((a[i].id - i)%k != 0) {
ok = false;
break;
}
ans += abs((a[i].id - i)/k);
}
if(!ok) cout << -1 << '\n';
else cout << ans/2 << '\n';
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
solve();
return 0;
}