結果
| 問題 | No.366 ロボットソート |
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2026-12-03 17:59:12 |
| 言語 | C++23(gcc16) (gcc 16.2.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 2 ms / 2,000 ms |
| + 271µs | |
| コード長 | 677 bytes |
| 記録 | |
| コンパイル時間 | 1,547 ms |
| コンパイル使用メモリ | 192,796 KB |
| 実行使用メモリ | 9,872 KB |
| 最終ジャッジ日時 | 2026-12-03 17:59:16 |
| 合計ジャッジ時間 | 3,902 ms |
|
ジャッジサーバーID (参考情報) |
judge3_0 / judge2_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
int f(vector<int>& a){
int n=a.size(), ans=0;
for(int i=0; i<n-1; i++)for(int j=i+1; j<n; j++) ans+=(a[i]>a[j]);
return ans;
}
int main(void){
int n, k; cin >> n >> k;
vector<int> a(n), b;
for(auto&x:a) cin >> x;
b=a;
sort(begin(b), end(b));
int ans=0;
for(int i=0; i<k; i++){
vector<int> now;
int id=i, c=0;
while(id<n){
now.push_back(a[id]);
id+=k;
}
ans+=f(now);
sort(begin(now), end(now));
id=i;
while(id<n) a[id]=now[c++], id+=k;
}
if(a==b) cout << ans << endl;
else cout << -1 << endl;
return 0;
}