結果

問題 No.397 NO MORE KADOMATSU
ユーザー pazzle1230pazzle1230
提出日時 2016-07-15 22:45:50
言語 C++11
(gcc 11.4.0)
結果
AC  
実行時間 54 ms / 2,000 ms
コード長 1,331 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 77,864 KB
実行使用メモリ 24,420 KB
平均クエリ数 651.67
最終ジャッジ日時 2023-09-24 00:13:54
合計ジャッジ時間 2,393 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,424 KB
testcase_01 AC 26 ms
24,420 KB
testcase_02 AC 25 ms
23,424 KB
testcase_03 AC 27 ms
23,412 KB
testcase_04 AC 25 ms
24,408 KB
testcase_05 AC 27 ms
23,676 KB
testcase_06 AC 28 ms
24,048 KB
testcase_07 AC 27 ms
24,264 KB
testcase_08 AC 27 ms
23,808 KB
testcase_09 AC 25 ms
23,580 KB
testcase_10 AC 54 ms
24,288 KB
testcase_11 AC 25 ms
23,460 KB
testcase_12 AC 26 ms
23,580 KB
testcase_13 AC 35 ms
24,300 KB
testcase_14 AC 34 ms
24,300 KB
testcase_15 AC 37 ms
24,348 KB
testcase_16 AC 25 ms
24,036 KB
testcase_17 AC 26 ms
24,384 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>

#define INF_LL 9000000000000000000
#define INF 2000000000

#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

class Union_find{
private:
	vector<int> par;
	vector<int> rank;
	int n;

public:
	Union_find(int a){
		n = a;
		for(int i = 0;i < n;i++){
			par.push_back(i);
			rank.push_back(0);
		}
	}

	int find(int x){
		if(par[x] == x){
			return x;
		}else{
			return par[x] = find(par[x]);
		}
	}

	void unite(int x, int y){
		x = find(x);
		y = find(y);
		if(x == y) return;

		if(rank[x] < rank[y]){
			par[x] = y;
		}else{
			par[y] = x;
			if(rank[x] == rank[y]) rank[x]++;
		}
	}

	bool same(int x, int y){
		return find(x) == find(y);
	}
};

int main(void){
	int n;
	int a[100];
	int dummy;
	vector< PII > s;
	int cnt = 0;
	cin >> n;
	REP(i, n){
		cin >> a[i];
	}

	for(int i = 0;i < n-1;i++){
		for(int j = i;j < n;j++){
			if(a[i] > a[j]){
				s.push_back(PII(i, j));
				swap(a[i], a[j]);
				cnt++;
			}
		}
	}
	cout << cnt << endl;
	REP(i, s.size()){
		cout << s[i].first << " " << s[i].second << endl;
	}

	cout << flush;
	cin >> dummy;
	return 0;
}
0