結果

問題 No.397 NO MORE KADOMATSU
ユーザー purple_jwlpurple_jwl
提出日時 2016-07-15 22:52:44
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 30 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 1,182 ms
コンパイル使用メモリ 148,596 KB
実行使用メモリ 24,408 KB
平均クエリ数 36.83
最終ジャッジ日時 2023-09-24 00:14:50
合計ジャッジ時間 2,882 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 30 ms
23,928 KB
testcase_01 AC 25 ms
23,820 KB
testcase_02 AC 25 ms
24,132 KB
testcase_03 AC 25 ms
23,448 KB
testcase_04 AC 25 ms
24,252 KB
testcase_05 AC 25 ms
23,688 KB
testcase_06 AC 26 ms
24,036 KB
testcase_07 AC 25 ms
23,700 KB
testcase_08 AC 25 ms
23,892 KB
testcase_09 AC 25 ms
24,120 KB
testcase_10 AC 25 ms
24,036 KB
testcase_11 AC 25 ms
24,288 KB
testcase_12 AC 26 ms
24,408 KB
testcase_13 AC 26 ms
24,288 KB
testcase_14 AC 25 ms
23,676 KB
testcase_15 AC 26 ms
23,424 KB
testcase_16 AC 25 ms
24,144 KB
testcase_17 AC 26 ms
23,568 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep (i, n) cin >> a[i];

    int cnt = 0;
    vector<pair<int, int>> p;
    rep (i, n) {
        int minv = a[i];
        int idx = i;
        REP (j, i + 1, n) {
            if (minv > a[j]) {
                minv = a[j];
                idx = j;
            }
        }
        if (idx != i) {
            cnt++;
            p.eb(mp(i, idx));
            swap(a[i], a[idx]);
        }
    }

    cout << cnt << endl;
    rep (i, sz(p)) {
        cout << p[i].F << ' ' << p[i].S << endl;
    }

    int tmp;
    cin >> tmp;
}
0