結果

問題 No.397 NO MORE KADOMATSU
ユーザー bal4ubal4u
提出日時 2019-07-14 05:41:42
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 32 ms / 2,000 ms
コード長 1,113 bytes
コンパイル時間 193 ms
コンパイル使用メモリ 29,792 KB
実行使用メモリ 24,288 KB
平均クエリ数 36.83
最終ジャッジ日時 2023-09-24 02:17:11
合計ジャッジ時間 1,921 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 32 ms
24,060 KB
testcase_01 AC 23 ms
23,628 KB
testcase_02 AC 23 ms
23,448 KB
testcase_03 AC 23 ms
24,288 KB
testcase_04 AC 24 ms
23,400 KB
testcase_05 AC 24 ms
23,508 KB
testcase_06 AC 23 ms
23,400 KB
testcase_07 AC 23 ms
23,640 KB
testcase_08 AC 23 ms
23,388 KB
testcase_09 AC 23 ms
23,508 KB
testcase_10 AC 24 ms
23,640 KB
testcase_11 AC 22 ms
24,000 KB
testcase_12 AC 23 ms
24,204 KB
testcase_13 AC 24 ms
24,252 KB
testcase_14 AC 25 ms
23,424 KB
testcase_15 AC 24 ms
23,460 KB
testcase_16 AC 24 ms
23,448 KB
testcase_17 AC 23 ms
24,060 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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

#include <stdio.h>

#if 0
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif
int in() {   // 非負整数の入力
	int n = 0, c = gc();
	do n = 10 * n + (c & 0xf); while ((c = gc()) >= '0');
	return n;
}

void out(int n) { // 非負整数の表示(出力)
	int i;
	char b[20];

	if (!n) pc('0');
	else {
		i = 0; while (n) b[i++] = n % 10 + '0', n /= 10;
		while (i--) pc(b[i]);
	}
}

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;

	N = in();
	mi = 101; for (i = 0; i < N; i++) {
		if ((a[i] = in()) < 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);
	}
	out(sz), pc('\n');
	for (i = 0; i < sz; i++) out(t[i].u), pc(' '), out(t[i].v), pc('\n');
	fflush(stdout);
	N = in();
	return 0;
}
0