結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 27 ms
23,592 KB
testcase_01 AC 19 ms
24,132 KB
testcase_02 AC 20 ms
23,448 KB
testcase_03 AC 35 ms
23,808 KB
testcase_04 AC 21 ms
24,420 KB
testcase_05 AC 27 ms
24,300 KB
testcase_06 AC 22 ms
23,412 KB
testcase_07 AC 25 ms
23,448 KB
testcase_08 AC 21 ms
24,048 KB
testcase_09 AC 20 ms
23,664 KB
testcase_10 AC 20 ms
23,928 KB
testcase_11 AC 20 ms
23,700 KB
testcase_12 AC 28 ms
23,568 KB
testcase_13 AC 29 ms
24,348 KB
testcase_14 AC 29 ms
23,436 KB
testcase_15 AC 34 ms
24,108 KB
testcase_16 AC 24 ms
24,036 KB
testcase_17 AC 23 ms
24,000 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