結果

問題 No.397 NO MORE KADOMATSU
ユーザー CleyLCleyL
提出日時 2022-01-02 08:31:47
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,387 bytes
コンパイル時間 879 ms
コンパイル使用メモリ 81,588 KB
実行使用メモリ 24,420 KB
平均クエリ数 33.44
最終ジャッジ日時 2023-09-24 03:01:30
合計ジャッジ時間 2,557 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,372 KB
testcase_01 AC 23 ms
23,652 KB
testcase_02 AC 23 ms
23,700 KB
testcase_03 AC 24 ms
24,072 KB
testcase_04 AC 23 ms
23,232 KB
testcase_05 AC 23 ms
24,384 KB
testcase_06 AC 24 ms
23,688 KB
testcase_07 AC 23 ms
23,904 KB
testcase_08 AC 24 ms
23,592 KB
testcase_09 AC 22 ms
24,096 KB
testcase_10 AC 22 ms
24,108 KB
testcase_11 AC 22 ms
23,364 KB
testcase_12 AC 23 ms
24,312 KB
testcase_13 AC 24 ms
23,628 KB
testcase_14 AC 26 ms
23,700 KB
testcase_15 AC 25 ms
23,400 KB
testcase_16 AC 23 ms
24,420 KB
testcase_17 AC 23 ms
24,372 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
    int n;cin>>n;
    vector<int> A(n),B(n),C(n);
    for(int i = 0; n > i; i++){
        cin>>A[i];
        B[i] = A[i];
        C[i] = A[i];
    }
    sort(B.begin(),B.end());
    vector<pair<int,int>> ret;
    for(int i = 0; n > i; i++){
        for(int j = i; n > j; j++){
            if(B[i] == A[j]){
                if(i!=j){
                    ret.push_back({i,j});
                    swap(A[i],A[j]);
                }
                break;
            }
        }
    }
    for(int i = 0; n > i; i++){
      A[i] = C[i];
    }
    sort(B.begin(),B.end(),greater<int>());
    vector<pair<int,int>> ret2;
    for(int i = 0; n > i; i++){
        for(int j = i; n > j; j++){
            if(B[i] == A[j]){
                if(i!=j){
                    ret2.push_back({i,j});
                    swap(A[i],A[j]);
                }
                break;
            }
        }
    }
    if(ret.size() < ret2.size()){
        cout << ret.size() << endl;
        for(int i = 0; ret.size() > i; i++){
            cout << ret[i].first << " " << ret[i].second << endl;
        }
    }else{
        cout << ret2.size() << endl;
        for(int i = 0; ret2.size() > i; i++){
            cout << ret2[i].first << " " << ret2[i].second << endl;
        }
    }
    int dm;cin>>dm;
    return 0;
}
0