結果

問題 No.366 ロボットソート
ユーザー hogeover30hogeover30
提出日時 2016-04-29 23:15:36
言語 C++11
(gcc 11.4.0)
結果
MLE  
実行時間 -
コード長 684 bytes
コンパイル時間 888 ms
コンパイル使用メモリ 84,764 KB
実行使用メモリ 547,616 KB
最終ジャッジ日時 2024-04-15 05:53:10
合計ジャッジ時間 4,498 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
13,756 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 1 ms
6,940 KB
testcase_03 AC 1 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 1 ms
6,944 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 3 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 3 ms
6,944 KB
testcase_10 MLE -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
using namespace std;

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

    queue<vector<int>> q;
    map<vector<int>, int> v;
    q.push(a);
    v[a]=0;

    while (q.size()) {
        auto p=q.front(); q.pop();
        if (is_sorted(begin(p), end(p))) {
            cout<<v[p]<<endl;
            return 0;
        }
        int x=v[p];
        for(int i=0; i+k<n; ++i) {
            swap(p[i], p[i+k]);
            if (!v.count(p)) {
                v[p]=x+1;
                q.push(p);
            }
            swap(p[i], p[i+k]);
        }
    }
    cout<<-1<<endl;
}
0