結果

問題 No.1854 Limited Bubble Sort
ユーザー t_mkt_mk
提出日時 2022-03-16 09:36:49
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 897 bytes
コンパイル時間 2,046 ms
コンパイル使用メモリ 179,444 KB
実行使用メモリ 4,368 KB
最終ジャッジ日時 2023-10-24 14:06:13
合計ジャッジ時間 7,056 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0;i < (n);i++)
int main(){
  int t;
  cin >> t;
  vector<vector<int>> ans(t);

  rep(i,t){
    int n;
    cin >> n;
    vector<int> p(n);
    map<int,int> mp;
    rep(j,n) cin >> p[j],mp[--p[j]] = j;
    rep(j,n){
      int cnt = mp[j];
      if(p[cnt] == cnt)continue;
      cnt--;
      int flag = 1;
      while(cnt >= j ){
        if(p[cnt] == cnt){
          flag = -1;break;
        }else swap(p[cnt],p[cnt+1]);
        ans[i].push_back(cnt+1);
        cnt--;
      }
      if(flag == -1){
        ans[i].clear();
        ans[i].push_back(-1);
        break;
      }
    }
  }

  rep(i,t){
    if(ans[i].size() == 1 && ans[i][0] == -1)cout << -1 << endl;
    else{
      cout << ans[i].size() << endl;
      rep(j,ans[i].size()){
        cout << ans[i][j] << " ";
      }
      cout << endl;
    }
  }
  return 0;
}
0