結果
| 問題 |
No.366 ロボットソート
|
| コンテスト | |
| ユーザー |
ga0o
|
| 提出日時 | 2017-02-27 23:58:49 |
| 言語 | C++11(廃止可能性あり) (gcc 13.3.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 1,016 bytes |
| コンパイル時間 | 1,132 ms |
| コンパイル使用メモリ | 161,536 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-06-11 20:14:31 |
| 合計ジャッジ時間 | 2,050 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 23 |
ソースコード
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
#define len(n) (int)n.length()
#define pb push_back
#define ll long long
#define make_pair mkp
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n-1;i >= 0;i--)
#define ALL(v) (v).begin(), (v).end()
#ifdef DBGPRT
#define dbg(n) cerr << "//" << #n << ":" << n <<endl
#else
#define dbg(n) ;
#endif
typedef pair<ll, ll> LLARR;
#define INF 999999999
const double PI = 3.1415926535897932384626433832795;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int main()
{
ios::sync_with_stdio(false);
ll n,k;
cin >> n >> k;
vector<ll> v;
REP(i,n)
{
ll t;cin >> t;
v.pb(t);
}
ll ans = 0;
REP(i, n-1)
{
dbg(i);
for(int j = i; j < n; j+=k)
{
dbg(j);
if (v[i] > v[j])
{
ll tmp = v[i];
v[i] = v[j];
v[j] = tmp;
ans++;
}
}
}
dbg("");
for(auto i:v) dbg(i);
bool f = true;
REP(i, n-1)
{
if (v[i] > v[i+1])
f = false;
}
cout << (f ? ans : -1) << endl;
return 0;
}
ga0o