結果
問題 | No.366 ロボットソート |
ユーザー |
|
提出日時 | 2016-12-24 00:20:15 |
言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 978 bytes |
コンパイル時間 | 1,005 ms |
コンパイル使用メモリ | 88,760 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 18:35:13 |
合計ジャッジ時間 | 2,201 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#define _USE_MATH_DEFINES #include<stdio.h> #include<string> #include<iostream> #include<cctype> #include<cstdio> #include<vector> #include<stack> #include<queue> #include <algorithm> #include<math.h> #include<set> #include<map> #include<iomanip> //#include<bits/stdc++.h> using namespace std; int main() { int n, k; cin >> n >> k; vector<int>a, b; for (int i = 0; i < n; i++) { int r; cin >> r; a.push_back(r), b.push_back(r); } sort(b.begin(), b.end()); int s = 0; vector<int>x[1030],y[1030]; for (int i = 0; i < n; i++) { x[i%k].push_back(a[i]); y[i%k].push_back(b[i]); } for (int i = 0; i < k; i++) { for (int j = 0; j < x[i].size(); j++) { for (int w = x[i].size() - 1; w > j; w--) { //cout << x[i][w]; if (x[i][w] < x[i][w - 1]) { swap(x[i][w], x[i][w - 1]); s++; } } } } for (int i = 0; i <= 1000; i++) { if (x[i] != y[i]) { cout << -1 << endl; return 0; } } cout << s << endl; return 0; }