結果

問題 No.14 最小公倍数ソート
ユーザー bal4ubal4u
提出日時 2019-04-30 21:45:54
言語 C
(gcc 12.3.0)
結果
RE  
実行時間 -
コード長 1,240 bytes
コンパイル時間 314 ms
コンパイル使用メモリ 30,164 KB
実行使用メモリ 4,500 KB
最終ジャッジ日時 2023-08-30 03:42:55
合計ジャッジ時間 1,682 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 0 ms
4,376 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 RE -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: 関数 ‘in’ 内:
main.c:8:14: 警告: 関数 ‘getchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    8 | #define gc() getchar_unlocked()
      |              ^~~~~~~~~~~~~~~~
main.c:16:24: 備考: in expansion of macro ‘gc’
   16 |         int n = 0, c = gc();
      |                        ^~
main.c: 関数 ‘out’ 内:
main.c:9:15: 警告: 関数 ‘putchar_unlocked’ の暗黙的な宣言です [-Wimplicit-function-declaration]
    9 | #define pc(c) putchar_unlocked(c)
      |               ^~~~~~~~~~~~~~~~
main.c:26:17: 備考: in expansion of macro ‘pc’
   26 |         if (sp) pc(' ');
      |                 ^~

ソースコード

diff #

// yukicoder: No.14 最小公倍数ソート
// 2019.4.30 bal4u

#include <stdio.h>
#include <stdlib.h>

#if 1
#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), c = gc(); while (c >= '0');
	return n;
}

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

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

int N;
int a[10005];
int f[10005];

int cmp(const void *a, const void *b) { return *(int *)a - *(int *)b; }

int main()
{
	int i, j, k, N;

	N = in();
	for (i = 0; i < N; i++) a[i] = in(), f[a[i]]++;
	qsort(a+1, N-1, sizeof(int), cmp);
	out(a[0], 0), f[a[0]]--;
	i = 1, j = N-1;
	while (a[i] == 1) out(1, 1), f[1]--, i++, j--;
	while (j > 0) {
		while (a[i] == a[i-1]) out(a[i], 1), f[a[i]]--, i++, j--;
		if (j > 0) {
			int t = i-1;
			while (!f[a[i]]) i++;		
			for (k = 2; k < a[i]; k++) {
				if (f[k*a[t]]) {
					out(k*a[t], 1), f[k*a[t]]--, j--;
					break;
				}
			}
			if (k == a[i]) out(a[i], 1), f[a[i]]--, i++, j--;
		}
	}
	pc('\n');
	return 0;
}
0