結果

問題 No.548 国士無双
ユーザー fkwnw3_1243fkwnw3_1243
提出日時 2017-09-06 22:50:33
言語 Java19
(openjdk 21)
結果
WA  
実行時間 -
コード長 1,788 bytes
コンパイル時間 4,571 ms
コンパイル使用メモリ 74,556 KB
実行使用メモリ 51,200 KB
最終ジャッジ日時 2023-09-19 08:42:33
合計ジャッジ時間 5,832 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 AC 44 ms
49,420 KB
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 44 ms
49,344 KB
testcase_21 WA -
testcase_22 AC 43 ms
49,452 KB
testcase_23 AC 45 ms
49,128 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.System.in;

public class No548 {
    public static void main(String[] args) throws IOException {

        BufferedReader reader = new BufferedReader(new InputStreamReader(in));

        String S = reader.readLine();

        int[] table = new int[13];

        for (int i = 0; i < 13; i++) {
            int characterAsInt = S.charAt(i) - 97;
            if (0 <= characterAsInt && characterAsInt <= 12) {
                table[characterAsInt] += 1;
            }
        }

        if (allOne(table)) {
            for (int i = 0; i < 13; i++) {
                System.out.println((char) (97 + i));
            }
        } else if (one2AndEleven1AndOne0(table)) {
            for (int i = 0; i < 13; i++) {
                if(table[i] == 0) {
                    System.out.println((char) (table[i] + 97));
                }
            }
        } else {
            System.out.println("Impossible");
        }


    }

    private static boolean allOne(int[] table) {

        for (int i = 0; i < 13; i++) {
            if (table[i] != 1) {
                return false;
            }
        }
        return true;
    }

    private static boolean one2AndEleven1AndOne0(int[] table) {

        int counterFor2 = 0;
        int counterFor1 = 0;
        int counterFor0 = 0;

        for (int i = 0; i < 13; i++) {
            if (table[i] == 2) {
                counterFor2 += 1;
            } else if (table[i] == 1) {
                counterFor1 += 1;
            } else if (table[i] == 0) {
                counterFor0 += 1;
            }
        }

        return (counterFor2 == 1) && (counterFor1 == 11) && (counterFor0 == 1);
    }
}
0