結果
| 問題 | No.366 ロボットソート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-02-10 16:04:34 |
| 言語 | C++17 (gcc 15.2.0 + boost 1.89.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,041 bytes |
| 記録 | |
| コンパイル時間 | 2,946 ms |
| コンパイル使用メモリ | 217,972 KB |
| 実行使用メモリ | 8,096 KB |
| 最終ジャッジ日時 | 2026-02-10 16:04:39 |
| 合計ジャッジ時間 | 4,320 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 5 WA * 13 RE * 5 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
const int N = 305;
int a[N] , c[N];
pair<int,pair<int,int>> b[N];
bool vis[N];
int main(){
cin.tie(0)->sync_with_stdio(0);
int n , k;
memset(vis,false,sizeof(vis));
bool kt = true;
cin >> n;
for(int i = 1; i <= n ; i ++){
cin >> a[i];
b[i].first = a[i];
b[i].second.first = i;
}
cin >> k;
sort(b + 1, b + n + 1);
int x = 0;
for(int i = 1 ; i <= n ; i ++){
b[i].second.second = i;
}
for(int i = 1; i <= n ;i ++){
if(abs(b[i].second.second - b[i].second.first) % k != 0){
cout << -1;
return 0;
}
}
for(int i = 1; i <= n; i++){
c[b[i].second.first] = b[i].second.second;
}
int ans = 0;
for(int i = 1; i <= n; i++){
if(vis[i] || c[i] == i) continue;
int cur = i, len = 0;
while(!vis[cur]){
vis[cur] = true;
cur = c[cur];
len++;
}
ans += len - 1;
}
cout << ans;
}