結果

問題 No.366 ロボットソート
ユーザー CleyLCleyL
提出日時 2020-03-05 22:46:22
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 795 bytes
コンパイル時間 621 ms
コンパイル使用メモリ 74,276 KB
実行使用メモリ 6,948 KB
最終ジャッジ日時 2024-04-22 03:19:24
合計ジャッジ時間 1,548 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 WA -
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 2 ms
5,376 KB
testcase_08 WA -
testcase_09 AC 1 ms
5,376 KB
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 AC 1 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 1 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 2 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 WA -
testcase_21 AC 3 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[k];
  for(int i = 0; n > i; i++){
    int t;cin>>t;
    A[i%k].push_back(t);
  }
  for(int i = 0; k > i; i++){
    Bsort(A[i].begin(),A[i].end());
  }
  int nw = -1;
  for(int i = 0; n > i; i++){
    for(int j = 0; k > j; j++){
      if(!A[j].empty())break;
      if(!A[j][i])break;
      if(nw > A[j][i]){
        cout << -1 << endl;
        return 0;
      }
      nw = A[j][i];
    }
  }
  cout << ans << endl;

}
0