結果

問題 No.1644 Eight Digits
ユーザー 👑 ygussanyygussany
提出日時 2021-08-01 11:24:13
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 2 ms / 1,000 ms
コード長 630 bytes
コンパイル時間 1,092 ms
コンパイル使用メモリ 28,928 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-07-27 02:47:23
合計ジャッジ時間 1,337 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 2 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,380 KB
testcase_08 AC 1 ms
4,376 KB
testcase_09 AC 2 ms
4,380 KB
testcase_10 AC 2 ms
4,380 KB
testcase_11 AC 2 ms
4,380 KB
testcase_12 AC 2 ms
4,380 KB
testcase_13 AC 2 ms
4,376 KB
testcase_14 AC 2 ms
4,380 KB
testcase_15 AC 2 ms
4,376 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 2 ms
4,384 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 2 ms
4,380 KB
testcase_21 AC 2 ms
4,376 KB
testcase_22 AC 2 ms
4,380 KB
testcase_23 AC 2 ms
4,376 KB
testcase_24 AC 2 ms
4,380 KB
testcase_25 AC 2 ms
4,380 KB
testcase_26 AC 2 ms
4,376 KB
testcase_27 AC 2 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <stdio.h>

int next_permutation(int N, int p[])
{
	static int i, j, q[10] = {};
	for (i = N; i > 1; i--) {
		q[p[i]] = 1;
		if (p[i] > p[i-1]) break;
	}
	if (i == 1) return 0;
	
	q[p[i-1]] = 1;
	for (j = p[i-1] + 1; q[j] == 0; j++);
	p[i-1] = j;
	q[j] = 0;
	for (j = 1; i <= N; i++) {
		for (; q[j] == 0; j++);
		p[i] = j;
		q[j++] = 0;
	}
	return 1;
}

int main()
{
	int i, k, K, p[10], ans = 0;
	scanf("%d", &K);
	for (i = 1; i <= 8; i++) p[i] = i;
	do {
		for (i = 1, k = 0; i <= 8; i++) k = k * 10 + p[i];
		if (k % K == 0) ans++;
	} while (next_permutation(8, p));
	printf("%d\n", ans);
	fflush(stdout);
	return 0;
}
0