結果
問題 | No.366 ロボットソート |
ユーザー |
![]() |
提出日時 | 2016-04-29 22:43:38 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 3 ms / 2,000 ms |
コード長 | 876 bytes |
コンパイル時間 | 1,994 ms |
コンパイル使用メモリ | 176,432 KB |
実行使用メモリ | 6,820 KB |
最終ジャッジ日時 | 2024-12-29 17:39:45 |
合計ジャッジ時間 | 2,950 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h>using namespace std;#define int long long#define REP(i,n) for(int i = 0; i < (int)(n); ++i)#define DEBUG(x) cerr << #x << " = " << x << endlbool check(vector<int> A, vector<vector<int>> S, int K) {sort(A.begin(), A.end());REP(i,S.size()) {sort(S[i].begin(), S[i].end());}REP(i,A.size()) {if(A[i] != S[i % K][i / K]) return false;}return true;}int bubble_sort(const vector<int>& ary) {int ans = 0;REP(i,ary.size()) {REP(j,i) {if(ary[j] > ary[i]) ans++;}}return ans;}signed main() {int N, K; cin >> N >> K;vector<int> A(N);REP(i,N) cin >> A[i];vector<vector<int>> S(K);REP(i,N) {S[i % K].push_back(A[i]);}if(check(A, S, K) == false) {cout << -1 << endl;}else {int ans = 0;REP(i,K) ans += bubble_sort(S[i]);cout << ans << endl;}}