結果
問題 | No.366 ロボットソート |
ユーザー | roiti46 |
提出日時 | 2016-04-29 23:07:45 |
言語 | C++11 (gcc 13.3.0) |
結果 |
AC
|
実行時間 | 248 ms / 2,000 ms |
コード長 | 877 bytes |
コンパイル時間 | 1,534 ms |
コンパイル使用メモリ | 159,256 KB |
実行使用メモリ | 5,248 KB |
最終ジャッジ日時 | 2024-12-29 17:42:25 |
合計ジャッジ時間 | 2,763 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 23 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; template<typename T> using Graph = vector<vector<T>>; #define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++) #define rep(i, a) REP(i, 0, a) #define EACH(i, a) for (auto i: a) #define ITR(x, a) for (__typeof(a.begin()) x = a.begin(); x != a.end(); x++) #define ALL(a) (a.begin()), (a.end()) #define HAS(a, x) (a.find(x) != a.end()) #define endl '\n' int N, K; int a[1005]; int main(void) { cin.tie(0); ios::sync_with_stdio(false); cin >> N >> K; rep(i, N) cin >> a[i]; int i = 0, ans = 0; while (i < N - K) { if (a[i] > a[i + K]) { swap(a[i], a[i + K]); ans++; i = 0; } else { i++; } } int mn = 1e9; rep(i, N - 1) mn = min(mn, a[i + 1] - a[i]); if (mn >= 1) { cout << ans << endl; } else { cout << -1 << endl; } return 0; }