結果

問題 No.397 NO MORE KADOMATSU
ユーザー koyumeishikoyumeishi
提出日時 2016-07-09 02:35:57
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 47 ms / 2,000 ms
コード長 472 bytes
コンパイル時間 613 ms
コンパイル使用メモリ 71,788 KB
実行使用メモリ 24,408 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 00:10:46
合計ジャッジ時間 2,052 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 26 ms
23,412 KB
testcase_01 AC 22 ms
23,544 KB
testcase_02 AC 22 ms
23,652 KB
testcase_03 AC 23 ms
23,448 KB
testcase_04 AC 23 ms
23,688 KB
testcase_05 AC 23 ms
23,808 KB
testcase_06 AC 25 ms
23,820 KB
testcase_07 AC 25 ms
24,408 KB
testcase_08 AC 21 ms
23,688 KB
testcase_09 AC 20 ms
23,448 KB
testcase_10 AC 47 ms
23,664 KB
testcase_11 AC 21 ms
23,664 KB
testcase_12 AC 31 ms
23,580 KB
testcase_13 AC 32 ms
23,400 KB
testcase_14 AC 34 ms
23,688 KB
testcase_15 AC 31 ms
23,844 KB
testcase_16 AC 19 ms
23,652 KB
testcase_17 AC 20 ms
23,400 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 && 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