結果

問題 No.397 NO MORE KADOMATSU
ユーザー face4face4
提出日時 2018-05-24 20:21:39
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 25 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 536 ms
コンパイル使用メモリ 70,628 KB
実行使用メモリ 24,276 KB
平均クエリ数 36.83
最終ジャッジ日時 2023-09-24 01:46:16
合計ジャッジ時間 2,045 ms
ジャッジサーバーID
(参考情報)
judge14 / judge11
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 25 ms
23,496 KB
testcase_01 AC 19 ms
24,192 KB
testcase_02 AC 23 ms
24,276 KB
testcase_03 AC 21 ms
24,192 KB
testcase_04 AC 19 ms
23,508 KB
testcase_05 AC 23 ms
23,844 KB
testcase_06 AC 22 ms
24,060 KB
testcase_07 AC 23 ms
23,388 KB
testcase_08 AC 21 ms
23,244 KB
testcase_09 AC 21 ms
23,796 KB
testcase_10 AC 21 ms
24,204 KB
testcase_11 AC 20 ms
23,232 KB
testcase_12 AC 22 ms
24,036 KB
testcase_13 AC 21 ms
23,532 KB
testcase_14 AC 20 ms
23,232 KB
testcase_15 AC 24 ms
23,388 KB
testcase_16 AC 20 ms
23,256 KB
testcase_17 AC 20 ms
23,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

int main(){
    int n;
    cin >> n;

    vector<pair<int,int>> res;
    int A[n];
    for(int i = 0; i < n; i++)  cin >> A[i];

    for(int i = 0; i < n-1; i++){
        int min = A[i];
        int minIndex = i;
        for(int j = i+1; j < n; j++){
            if(min > A[j]){
                min = A[j];
                minIndex = j;
            }
        }

        if(i != minIndex){
            res.push_back({i, minIndex});
            swap(A[i],A[minIndex]);
        }
    }

    cout << res.size() << endl;
    for(pair<int,int> p : res){
        cout << p.first << " " << p.second << endl;
    }

    cin >> n; // dummy input
    return 0;
}
0