結果
| 問題 | No.366 ロボットソート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-10 17:08:20 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 948 bytes |
| 記録 | |
| コンパイル時間 | 1,119 ms |
| コンパイル使用メモリ | 121,808 KB |
| 実行使用メモリ | 7,972 KB |
| 最終ジャッジ日時 | 2026-02-10 17:08:23 |
| 合計ジャッジ時間 | 2,485 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 8 WA * 15 |
ソースコード
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <ctime>
#include <map>
using namespace std;
#define fi first
#define se second
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)
const long long mod = 1e9 + 7;
const long long mod1 = 1e9 + 4321, mod2 = 1e9 + 321;
const long long MAXN = 2e5 + 5;
const long long inf = 1e18;
//---------------------------------------------------
long long n, k, need[MAXN], real[MAXN], ans;
map<long long, long long> pos;
int main() {
cin >> n;
for(int i =1 ; i <= n; i ++)
{
cin >> need[i];
real[i] = need[i];
}
cin >> k;
sort(need + 1, need + n + 1);
for(int i =1 ; i <= n; i++)
{
pos[need[i]] = i;
}
for(int i = 1; i <= n; i ++)
{
if((pos[real[i]] - i) % k != 0)
{
cout << -1;
return 0;
}
//cout << pos[real[i]] << " " << i << "\n";
ans += abs(pos[real[i]] - i)/k;
}
cout << ans/2;
cerr << "Time elapsed: " << TIME << " s.\n";
return 0;
}