結果

問題 No.397 NO MORE KADOMATSU
ユーザー くれちーくれちー
提出日時 2016-12-28 19:28:37
言語 C90
(gcc 11.4.0)
結果
AC  
実行時間 28 ms / 2,000 ms
コード長 760 bytes
コンパイル時間 251 ms
コンパイル使用メモリ 24,696 KB
実行使用メモリ 24,360 KB
平均クエリ数 107.94
最終ジャッジ日時 2023-09-24 00:48:36
合計ジャッジ時間 2,214 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 28 ms
23,388 KB
testcase_01 AC 25 ms
24,360 KB
testcase_02 AC 25 ms
23,604 KB
testcase_03 AC 27 ms
23,604 KB
testcase_04 AC 26 ms
24,288 KB
testcase_05 AC 26 ms
24,312 KB
testcase_06 AC 25 ms
23,784 KB
testcase_07 AC 25 ms
23,532 KB
testcase_08 AC 25 ms
23,520 KB
testcase_09 AC 24 ms
24,300 KB
testcase_10 AC 24 ms
24,360 KB
testcase_11 AC 24 ms
23,376 KB
testcase_12 AC 24 ms
23,976 KB
testcase_13 AC 25 ms
23,604 KB
testcase_14 AC 26 ms
24,000 KB
testcase_15 AC 25 ms
23,376 KB
testcase_16 AC 25 ms
23,976 KB
testcase_17 AC 25 ms
23,964 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int ans[100][2];
int cnt = 0;

void swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

void sort(int *d, int s, int idx) {
	int i, l = 1;
	if (s < 2) return;
	for (i = 1; i < s; i++) {
		if (d[0] < d[i]) {
			if (l != i) {
				swap(&d[l], &d[i]);
				ans[cnt][0] = l + idx;
				ans[cnt][1] = i + idx;
				cnt++;
			}
			l++;
		}
	}
	if (l - 1 != 0) {
		swap(&d[0], &d[l - 1]);
		ans[cnt][0] = idx;
		ans[cnt][1] = l - 1 + idx;
		cnt++;
	}
	sort(d, l, idx);
	sort(d + l, s - l, idx + l);
}

int main() {
	int n;
	scanf("%d", &n);
	int a[100], i;
	for (i = 0; i < n; i++) scanf("%d", &a[i]);

	sort(a, n, 0);

	printf("%d\n", cnt);
	for (i = 0; i < cnt; i++)
		printf("%d %d\n", ans[i][0], ans[i][1]);
	fflush(stdout);
	return 0;
}
0