結果

問題 No.1644 Eight Digits
ユーザー ks2mks2m
提出日時 2021-08-13 21:26:38
言語 Java19
(openjdk 21)
結果
AC  
実行時間 230 ms / 1,000 ms
コード長 585 bytes
コンパイル時間 2,317 ms
コンパイル使用メモリ 72,836 KB
実行使用メモリ 60,364 KB
最終ジャッジ日時 2023-07-27 03:16:32
合計ジャッジ時間 9,570 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 227 ms
60,164 KB
testcase_01 AC 189 ms
59,772 KB
testcase_02 AC 190 ms
59,852 KB
testcase_03 AC 186 ms
59,896 KB
testcase_04 AC 230 ms
60,032 KB
testcase_05 AC 229 ms
60,164 KB
testcase_06 AC 208 ms
59,656 KB
testcase_07 AC 192 ms
59,948 KB
testcase_08 AC 189 ms
59,704 KB
testcase_09 AC 227 ms
60,064 KB
testcase_10 AC 214 ms
57,796 KB
testcase_11 AC 216 ms
59,716 KB
testcase_12 AC 228 ms
59,712 KB
testcase_13 AC 197 ms
59,976 KB
testcase_14 AC 215 ms
60,316 KB
testcase_15 AC 206 ms
59,716 KB
testcase_16 AC 227 ms
59,956 KB
testcase_17 AC 222 ms
60,016 KB
testcase_18 AC 211 ms
59,840 KB
testcase_19 AC 190 ms
57,920 KB
testcase_20 AC 187 ms
59,724 KB
testcase_21 AC 209 ms
60,080 KB
testcase_22 AC 212 ms
59,720 KB
testcase_23 AC 191 ms
59,820 KB
testcase_24 AC 191 ms
60,364 KB
testcase_25 AC 189 ms
59,932 KB
testcase_26 AC 189 ms
59,728 KB
testcase_27 AC 185 ms
59,724 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.LinkedHashSet;
import java.util.Scanner;

public class Main {
	static int k, ans;

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		k = sc.nextInt();
		sc.close();

		permutation(0, new LinkedHashSet<>());
		System.out.println(ans);
	}

	static void permutation(int x, LinkedHashSet<Integer> set) {
		if (x > 10000000) {
			if (x % k == 0) {
				ans++;
			}
			return;
		}

		for (int i = 1; i <= 8; i++) {
			if (!set.contains(i)) {
				set.add(i);
				permutation(x * 10 + i, set);
				set.remove(i);
			}
		}
	}
}
0