結果

問題 No.366 ロボットソート
ユーザー motimoti
提出日時 2016-04-29 23:34:35
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
MLE  
実行時間 -
コード長 1,492 bytes
コンパイル時間 1,422 ms
コンパイル使用メモリ 130,320 KB
実行使用メモリ 814,336 KB
最終ジャッジ日時 2024-04-15 06:02:20
合計ジャッジ時間 3,202 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,816 KB
testcase_02 AC 2 ms
6,816 KB
testcase_03 AC 1 ms
6,816 KB
testcase_04 AC 1 ms
6,948 KB
testcase_05 AC 1 ms
6,940 KB
testcase_06 AC 1 ms
6,940 KB
testcase_07 AC 91 ms
22,144 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 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 <cmath>
#include <vector>
#include <complex>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
#include <assert.h>
#include <array>
#include <cstdio>
#include <cstring>
#include <random>
#include <functional>
#include <numeric>
#include <bitset>

using namespace std;

struct before_main{before_main(){cin.tie(0); ios::sync_with_stdio(false);}} before_main;

#define REP(i,a,b) for(int i=a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define all(c) (c).begin(), (c).end()
#define zero(a) memset(a, 0, sizeof a)
#define minus(a) memset(a, -1, sizeof a)
template<class T1, class T2> inline bool minimize(T1 &a, T2 b) { return b < a && (a = b, 1); }
template<class T1, class T2> inline bool maximize(T1 &a, T2 b) { return a < b && (a = b, 1); }

typedef long long ll;
int const inf = 1<<29;

int main() {
  
  int N, K; cin >> N >> K;
  vector<int> v(N);
  rep(i, N) {
    cin >> v[i];
  }
  
  queue<pair<int, vector<int>>> q;
  q.emplace(0, v);

  auto u = v; sort(all(u));
  set<vector<int>> st = {v};

  while(!q.empty()) {
    int cost; vector<int> p; tie(cost, p) = q.front(); q.pop();

    if(u == p) { cout << cost << endl; return 0; }

    rep(i, N-K) {
      if(p[i] < p[i+K]) { continue; }
      swap(p[i], p[i+K]);
      if(st.count(p)) { continue; }
      q.emplace(cost+1, p);
      swap(p[i], p[i+K]);
    }
  }

  cout << -1 << endl;

  return 0;
}
0