結果

問題 No.548 国士無双
ユーザー htensaihtensai
提出日時 2019-12-07 17:02:35
言語 Java21
(openjdk 21)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 977 bytes
コンパイル時間 2,333 ms
コンパイル使用メモリ 71,916 KB
実行使用メモリ 56,328 KB
最終ジャッジ日時 2023-08-26 21:27:37
合計ジャッジ時間 6,319 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 102 ms
56,160 KB
testcase_01 AC 105 ms
55,504 KB
testcase_02 AC 105 ms
55,792 KB
testcase_03 AC 102 ms
56,196 KB
testcase_04 AC 102 ms
55,712 KB
testcase_05 AC 104 ms
56,164 KB
testcase_06 AC 100 ms
55,592 KB
testcase_07 AC 101 ms
56,256 KB
testcase_08 AC 100 ms
56,064 KB
testcase_09 AC 99 ms
56,236 KB
testcase_10 AC 99 ms
55,816 KB
testcase_11 AC 101 ms
55,612 KB
testcase_12 AC 108 ms
55,792 KB
testcase_13 AC 112 ms
56,328 KB
testcase_14 AC 105 ms
55,816 KB
testcase_15 AC 100 ms
55,864 KB
testcase_16 AC 101 ms
55,996 KB
testcase_17 AC 100 ms
55,648 KB
testcase_18 AC 102 ms
55,728 KB
testcase_19 AC 102 ms
56,056 KB
testcase_20 AC 104 ms
55,640 KB
testcase_21 AC 102 ms
56,008 KB
testcase_22 AC 102 ms
55,900 KB
testcase_23 AC 100 ms
56,076 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