結果

問題 No.397 NO MORE KADOMATSU
ユーザー imulanimulan
提出日時 2016-07-16 19:39:45
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 31 ms / 2,000 ms
コード長 963 bytes
コンパイル時間 1,519 ms
コンパイル使用メモリ 170,448 KB
実行使用メモリ 24,372 KB
平均クエリ数 36.83
最終ジャッジ日時 2023-09-24 00:21:50
合計ジャッジ時間 3,173 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
23,784 KB
testcase_01 AC 25 ms
23,604 KB
testcase_02 AC 25 ms
23,628 KB
testcase_03 AC 25 ms
24,012 KB
testcase_04 AC 25 ms
24,216 KB
testcase_05 AC 25 ms
23,364 KB
testcase_06 AC 25 ms
24,180 KB
testcase_07 AC 25 ms
23,508 KB
testcase_08 AC 25 ms
24,000 KB
testcase_09 AC 25 ms
23,664 KB
testcase_10 AC 25 ms
24,372 KB
testcase_11 AC 25 ms
24,012 KB
testcase_12 AC 25 ms
23,952 KB
testcase_13 AC 25 ms
23,388 KB
testcase_14 AC 25 ms
24,312 KB
testcase_15 AC 25 ms
23,628 KB
testcase_16 AC 25 ms
24,192 KB
testcase_17 AC 24 ms
24,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define each(itr,c) for(__typeof(c.begin()) itr=c.begin(); itr!=c.end(); ++itr)
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define fi first
#define se second

typedef pair<int,int> pi;

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

    //solve
    vector<pi> ans;
    rep(i,n)
    {
        int m=a[i];
        int idx=i;
        for(int j=i+1; j<n; ++j)
        {
            if(a[j]<m)
            {
                m=a[j];
                idx=j;
            }
        }

        if(idx!=i)
        {
            ans.pb(pi(i,idx));
            swap(a[i],a[idx]);
        }
    }

    //out
    cout << ans.size() << endl;
    rep(i,ans.size()) printf("%d %d\n", ans[i].fi, ans[i].se);
    cout << flush;

    //Dummy
    int D;
    cin >>D;
    return 0;
}
0