結果

問題 No.397 NO MORE KADOMATSU
ユーザー finefine
提出日時 2016-07-15 22:45:08
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 51 ms / 2,000 ms
コード長 672 bytes
コンパイル時間 1,734 ms
コンパイル使用メモリ 169,976 KB
実行使用メモリ 24,252 KB
平均クエリ数 936.56
最終ジャッジ日時 2023-09-24 00:13:57
合計ジャッジ時間 3,465 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
23,436 KB
testcase_01 AC 25 ms
24,132 KB
testcase_02 AC 23 ms
23,400 KB
testcase_03 AC 25 ms
23,400 KB
testcase_04 AC 24 ms
24,240 KB
testcase_05 AC 25 ms
23,808 KB
testcase_06 AC 28 ms
23,976 KB
testcase_07 AC 29 ms
23,988 KB
testcase_08 AC 25 ms
23,628 KB
testcase_09 AC 24 ms
23,496 KB
testcase_10 AC 51 ms
23,364 KB
testcase_11 AC 23 ms
23,688 KB
testcase_12 AC 34 ms
23,652 KB
testcase_13 AC 36 ms
23,688 KB
testcase_14 AC 37 ms
24,252 KB
testcase_15 AC 35 ms
23,808 KB
testcase_16 AC 24 ms
23,508 KB
testcase_17 AC 24 ms
23,352 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> P;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<P> ans;
    for (int i = 0; i < n - 1; i++) {
        for (int j = n - 1; j > i; j--) {
            if (a[j - 1] > a[j]) {
                ans.emplace_back(j - 1, j);
                swap(a[j - 1], a[j]);
            }
        }
    }
    int s = ans.size();
    cout << s << endl;
    for (int i = 0; i < s; i++) {
        cout << ans[i].first << " " << ans[i].second << endl;
    }
    int dummy;
    cin >> dummy;
    return 0;
}
0