結果

問題 No.397 NO MORE KADOMATSU
ユーザー bal4ubal4u
提出日時 2019-07-14 05:33:51
言語 C
(gcc 12.3.0)
結果
TLE  
実行時間 -
コード長 682 bytes
コンパイル時間 1,159 ms
コンパイル使用メモリ 28,348 KB
実行使用メモリ 23,964 KB
平均クエリ数 0.22
最終ジャッジ日時 2023-09-23 17:55:43
合計ジャッジ時間 4,364 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
23,964 KB
testcase_01 AC 23 ms
23,592 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

// yukicoder: No.397 NO MORE KADOMATSU
// 2019.7.14 bal4u

#include <stdio.h>

typedef struct { int u, v; } T;
T t[105]; int sz;
int a[105]; int N;

void swap(int u, int v) {
	int x;
	t[sz].u = u, t[sz++].v = v;
	x = a[u], a[u] = a[v], a[v] = x;
}

int main()
{
	int i, j, mi;

	scanf("%d", &N);
	mi = 101; for (i = 0; i < N; i++) {
		scanf("%d", a+i);
		if (a[i] < mi) mi = a[i], j = i;
	}
	if (j) swap(0, j);

	for (i = 1; i < N; i++) if (a[i] != a[i-1]) {
		mi = i;
		for (j = i+1; j < N; j++) if (a[j] < a[mi]) mi = j;
		if (mi != i) swap(i, mi);
	}
	printf("%d\n", sz);
	for (i = 0; i < sz; i++) printf("%d %d\n", t[i].u, t[i].v), fflush(stdout);
	scanf("%d", &N);
	return 0;
}
0