結果

問題 No.397 NO MORE KADOMATSU
ユーザー koyumeishikoyumeishi
提出日時 2016-07-09 02:40:51
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 483 bytes
コンパイル時間 903 ms
コンパイル使用メモリ 71,612 KB
実行使用メモリ 24,504 KB
平均クエリ数 165.78
最終ジャッジ日時 2023-09-23 11:00:36
合計ジャッジ時間 4,320 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,376 KB
testcase_01 AC 25 ms
23,376 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 24 ms
23,532 KB
testcase_10 AC 25 ms
23,352 KB
testcase_11 AC 25 ms
23,856 KB
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 25 ms
23,640 KB
testcase_17 AC 27 ms
23,448 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
using namespace std;

int main(){
  int n;
  cin >> n;
  vector<int> A(n);
  for(int& a : A) cin >> a;

  vector<int> u,v;
  for(int i=1; i<n; i++){
    int p = i;
    while(p-1>=0 && i-p < 5 && A[p-1] < A[p]){
      swap(A[p-1], A[p]);
      
      u.push_back(p-1);
      v.push_back(p);

      p--;
    }
  }

  cout << u.size() << endl;
  for(int i=0; i<u.size(); i++){
    cout << u[i] << " " << v[i] << endl;
  }

  cin >> n;
  return 0;
}
0