結果

問題 No.366 ロボットソート
ユーザー itezpaceitezpace
提出日時 2016-04-29 23:52:26
言語 C++11
(gcc 11.4.0)
結果
TLE  
実行時間 -
コード長 847 bytes
コンパイル時間 590 ms
コンパイル使用メモリ 60,564 KB
実行使用メモリ 14,016 KB
最終ジャッジ日時 2024-04-15 06:12:52
合計ジャッジ時間 4,043 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
10,016 KB
testcase_01 AC 1 ms
6,816 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 TLE -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
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 <vector>
using namespace std;

int N, K, a, cnt, l, e;
vector<int> v = {};

int check(){
  e = 0;
  for(int i = 1; i < N; i++){
    for(int j = 0; j < i; j++){
      if(v[i] < v[j]){
        e++;
        break;
      }
    }
  }

  if(e > 0){
    cout << -1 << endl;
    return 0;
  } else {
    cout << cnt << endl;
    return 0;
  }
}

int main() {
  cin >> N >> K;
  for(int i = 0; i < N; i++){
    cin >> a;
    v.push_back(a);
  }

  cnt = 0;
  l = 0;
  v.push_back(0);

  if(N < K){
    check();
    return 0;
  }

  while(1){
    for(int i = 0; i < N - K; i++){
      if(v[i] > v[i + K]){
        v[N] = v[i];
        v[i] = v[i + K];
        v[i + K] = v[N];
        cnt++;
        l = 0;
      } else {
        l++;
        if(l == N - K){
          check();
          return 0;
        }
      }
    }
  }
}
0