結果

問題 No.548 国士無双
ユーザー htensaihtensai
提出日時 2019-12-07 17:02:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 121 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 2,613 ms
コンパイル使用メモリ 83,892 KB
実行使用メモリ 41,532 KB
最終ジャッジ日時 2024-06-07 16:56:31
合計ジャッジ時間 6,118 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 111 ms
41,088 KB
testcase_01 AC 112 ms
40,624 KB
testcase_02 AC 116 ms
40,660 KB
testcase_03 AC 102 ms
39,952 KB
testcase_04 AC 114 ms
41,532 KB
testcase_05 AC 104 ms
39,572 KB
testcase_06 AC 114 ms
40,976 KB
testcase_07 AC 113 ms
41,208 KB
testcase_08 AC 115 ms
41,144 KB
testcase_09 AC 121 ms
41,396 KB
testcase_10 AC 118 ms
41,144 KB
testcase_11 AC 112 ms
41,128 KB
testcase_12 AC 112 ms
41,428 KB
testcase_13 AC 98 ms
39,528 KB
testcase_14 AC 113 ms
40,836 KB
testcase_15 AC 106 ms
39,784 KB
testcase_16 AC 114 ms
40,968 KB
testcase_17 AC 115 ms
40,964 KB
testcase_18 AC 112 ms
40,644 KB
testcase_19 AC 98 ms
39,528 KB
testcase_20 AC 100 ms
39,840 KB
testcase_21 AC 103 ms
40,572 KB
testcase_22 AC 105 ms
40,420 KB
testcase_23 AC 110 ms
40,936 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        char[] arr = sc.next().toCharArray();
        int[] counts = new int[13];
        for (char c : arr) {
            counts[c - 'a']++;
        }
        boolean has2 = false;
        char ans = 'c';
        for (int i = 0; i < 13; i++) {
            if (counts[i] > 2 || (counts[i] == 2 && has2)) {
                System.out.println("Impossible");
                return;
            } else if (counts[i] == 2) {
                has2 = true;
            } else if (counts[i] == 0) {
                ans = (char)(i + 'a');
            }
        }
        if (has2) {
            System.out.println(ans);
        } else {
            StringBuilder sb = new StringBuilder();
            for (int i = 0; i < 13; i++) {
                sb.append((char)(i + 'a')).append("\n");
            }
            System.out.print(sb);
        }
    }
}
0