結果

問題 No.397 NO MORE KADOMATSU
ユーザー kapokapo
提出日時 2016-07-17 12:07:07
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 29 ms / 2,000 ms
コード長 1,230 bytes
コンパイル時間 742 ms
コンパイル使用メモリ 72,788 KB
実行使用メモリ 24,324 KB
平均クエリ数 75.33
最終ジャッジ日時 2023-09-24 00:22:18
合計ジャッジ時間 2,317 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 29 ms
24,324 KB
testcase_01 AC 25 ms
23,508 KB
testcase_02 AC 24 ms
24,252 KB
testcase_03 AC 24 ms
23,664 KB
testcase_04 AC 24 ms
23,580 KB
testcase_05 AC 25 ms
23,580 KB
testcase_06 AC 25 ms
23,820 KB
testcase_07 AC 25 ms
23,832 KB
testcase_08 AC 25 ms
23,976 KB
testcase_09 AC 24 ms
24,024 KB
testcase_10 AC 25 ms
23,580 KB
testcase_11 AC 24 ms
23,364 KB
testcase_12 AC 25 ms
23,640 KB
testcase_13 AC 26 ms
23,964 KB
testcase_14 AC 26 ms
23,604 KB
testcase_15 AC 26 ms
23,496 KB
testcase_16 AC 25 ms
23,580 KB
testcase_17 AC 24 ms
24,024 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <sstream>
#include <cmath>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()

typedef pair<int, int> Pii;
typedef vector<int> V;
typedef long long ll;
const int inf = 1e9;
const int mod = 1e9 + 7;

int N;
int A[100] = {};
int cnt = 0;
V ans[2];

void quick_sort(int l, int r)
{
    if(l>=r) return;
    int p = l;
    int k = l+1;
    while(k<=r) {
        if(A[l]>A[k]) {
			if(A[p+1]!=A[k]){
				ans[0].pb(p+1);
				ans[1].pb(k);
				cnt++;
			}

            swap(A[p+1],A[k]);
            p++;
        }
        k++;
    }
	if(A[l]!=A[p]){
		ans[0].pb(l);
		ans[1].pb(p);
		cnt++;
	}

	swap(A[l],A[p]);
    quick_sort(l,p-1);
    quick_sort(p+1,r);
    return;
}

int main()
{
    cin >> N;
    rep(i,0,N) cin >> A[i];

    quick_sort(0,N-1);
    //rep(i,0,N) cout << A[i] << " "; cout << endl;

    cout << cnt << endl;
    rep(i,0,cnt) {
        cout << ans[0][i] << " " << ans[1][i] << endl;
    }
	
    cout << flush;
    cin >> N;

    return 0;
}
0