結果

問題 No.397 NO MORE KADOMATSU
ユーザー face4face4
提出日時 2018-05-24 20:21:39
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 24 ms / 2,000 ms
コード長 709 bytes
コンパイル時間 537 ms
コンパイル使用メモリ 72,656 KB
実行使用メモリ 25,220 KB
平均クエリ数 36.83
最終ジャッジ日時 2024-07-17 01:44:12
合計ジャッジ時間 1,969 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 18
権限があれば一括ダウンロードができます

ソースコード

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