結果

問題 No.443 GCD of Permutation
ユーザー hermione17hermione17
提出日時 2016-11-12 00:07:04
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,293 bytes
コンパイル時間 3,038 ms
コンパイル使用メモリ 74,040 KB
実行使用メモリ 58,576 KB
最終ジャッジ日時 2023-08-16 20:27:04
合計ジャッジ時間 8,118 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 112 ms
56,008 KB
testcase_02 AC 114 ms
55,912 KB
testcase_03 AC 112 ms
55,784 KB
testcase_04 AC 112 ms
56,172 KB
testcase_05 AC 111 ms
56,020 KB
testcase_06 AC 110 ms
55,804 KB
testcase_07 AC 111 ms
56,132 KB
testcase_08 AC 112 ms
53,684 KB
testcase_09 AC 112 ms
55,980 KB
testcase_10 AC 112 ms
55,700 KB
testcase_11 WA -
testcase_12 AC 113 ms
56,012 KB
testcase_13 AC 114 ms
56,148 KB
testcase_14 AC 132 ms
56,340 KB
testcase_15 AC 130 ms
56,252 KB
testcase_16 AC 117 ms
56,544 KB
testcase_17 AC 117 ms
56,476 KB
testcase_18 AC 128 ms
56,488 KB
testcase_19 AC 118 ms
56,184 KB
testcase_20 AC 130 ms
56,060 KB
testcase_21 AC 125 ms
55,800 KB
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 131 ms
55,828 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 130 ms
56,300 KB
testcase_29 WA -
testcase_30 AC 131 ms
56,204 KB
testcase_31 AC 130 ms
56,080 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.PrintStream;
import java.util.Scanner;


public class Y443 {
	Scanner in = new Scanner(System.in);
	PrintStream out = new PrintStream(System.out);

	Y443() throws Exception {
		String s = in.next();
		
		boolean[] flag = new boolean[10];
		
		if (isRepetitive(s)) {
			out.println(s);
			return;
		}
		
		int sum = 0;
		for (int i = 0; i < s.length(); i++) {
			sum += s.charAt(i) - '0';
		}

		if (sum % 9 == 0) {
			flag[9] = true;
		}
		if (sum % 3 == 0) {
			flag[3] = true;
		}
		
		for (int i = 1; i < 10; i++) {
			if (allDigitsDivided(s, i)) {
				flag[i] = true;
			}
		}
		
		if (flag[4]) flag[2] = false;
		if (flag[6]) {
			flag[2] = false;
			flag[3] = false;
		}
		if (flag[8]) flag[4] = false;
		if (flag[9]) flag[3] = false;
		
		int ans = 1;
		for (int i = 0; i < 10; i++) {
			if (flag[i]) {
				ans *= i;
			}
		}
		
		out.println(ans);
	}
	
	boolean isRepetitive(String s) {
		for (int i = 0; i < s.length(); i++) {
			if (s.charAt(0) != s.charAt(i)) {
				return false;
			}
		}
		return true;
	}

	boolean allDigitsDivided(String s, int x) {
		for (int i = 0; i < s.length(); i++) {
			int y = s.charAt(i) - '0';
			if (y % x > 0) {
				return false;
			}
		}
		return true;
	}
	public static void main(String argv[]) throws Exception {
		new Y443();
	}
}
0