結果

問題 No.366 ロボットソート
ユーザー CleyLCleyL
提出日時 2020-03-05 23:05:42
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 797 bytes
コンパイル時間 768 ms
コンパイル使用メモリ 74,056 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-22 03:36:34
合計ジャッジ時間 1,750 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int ans = 0;
void Bsort(vector<int>::iterator f, vector<int>::iterator l){
  for(auto e = f; e != l; e++){
    for(auto i = l-1; i != e; i--){
      auto j = i;
      j--;
      if(*i < *j){
        iter_swap(i,j);
        ans++;
      }
    }
  }
}
int main(){
  int n,k;cin>>n>>k;
  vector<int> A[min(n,k)];
  for(int i = 0; n > i; i++){
    int t;cin>>t;
    A[i%k].push_back(t);
  }
  for(int i = 0; min(n,k) > i; i++){
    Bsort(A[i].begin(),A[i].end());
  }
  int nw = -1;
  int z = n-1;
  for(int i = 0; n > i; i++){
    for(int j = 0; min(n,k) > j; j++){
      if(!--z)break;
      if(nw > A[j][i]){
        cout << -1 << endl;
        return 0;
      }
      nw = A[j][i];
    }
  }
  cout << ans << endl;

}
0