結果

問題 No.366 ロボットソート
ユーザー MotoSai114MotoSai114
提出日時 2016-05-09 20:00:33
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 869 bytes
コンパイル時間 1,306 ms
コンパイル使用メモリ 160,044 KB
実行使用メモリ 13,752 KB
最終ジャッジ日時 2024-04-15 14:56:59
合計ジャッジ時間 9,046 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include "bits/stdc++.h"
using namespace std;

void swap(int *x,int *y){
  int tmp = *x;
  *x=*y;
  *y=tmp;
}

int main(){
  int N,K,count=0,OK=0,OK2=0,FLAG=0;
  cin >> N >> K;
  int data[N];
  for(auto&& x: data)cin >> x;
  while(1){
    FLAG=1;
    if(K>=N) break;
    int j=0;
    for(int i=j;i<N;++i){
      for(;j<N-K;++j){
        OK=0;
        if(data[j]>data[j+K]){
          FLAG=0;
          break;
        }
        OK=1;
      }
      if(!OK){
        swap(&data[j],&data[j+K]);
        ++count;
      }else break;
      for(auto&& x: data)cout << x << " ";
      cout <<endl;
    }
    for(int i=0;i<N-1;++i){
      OK2=0;
      if(data[i]>data[i+1])break;
      OK2=1;
    }
    if(OK2||FLAG)break;
  }
  for(int i=0;i<N-1;++i){
    OK=0;
    if(data[i]>data[i+1])break;
    OK=1;
  }
  if(OK)cout << count <<endl;
  else cout << -1 <<endl;
  return 0;
}
0