結果

問題 No.366 ロボットソート
ユーザー hogeover30
提出日時 2016-06-23 00:03:58
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 4 ms / 2,000 ms
コード長 570 bytes
コンパイル時間 680 ms
コンパイル使用メモリ 72,136 KB
実行使用メモリ 5,248 KB
最終ジャッジ日時 2024-12-29 18:28:49
合計ジャッジ時間 1,603 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 23
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int sort(vector<int>& a, int s, int K)
{
    int n=a.size();
    int res=0;
    for(int i=s; i<n; i+=K) {
        for(int j=s; j+K<n; j+=K) {
            if (a[j]>a[j+K]) {
                swap(a[j], a[j+K]);
                ++res;
            }
        }
    }
    return res;
}

int main()
{
    int n, k; cin>>n>>k;
    vector<int> a(n); for(auto& e: a) cin>>e;

    int res=0;
    for(int i=0; i<k; ++i) res+=sort(a, i, k);

    cout<<(is_sorted(begin(a), end(a)) ? res : -1)<<endl;
}
0