結果

問題 No.233 めぐるはめぐる (3)
ユーザー htensaihtensai
提出日時 2020-05-12 17:34:32
言語 Java21
(openjdk 21)
結果
RE  
実行時間 -
コード長 1,493 bytes
コンパイル時間 2,189 ms
コンパイル使用メモリ 74,588 KB
実行使用メモリ 77,112 KB
最終ジャッジ日時 2023-10-11 17:20:46
合計ジャッジ時間 14,404 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 747 ms
75,424 KB
testcase_01 AC 574 ms
67,568 KB
testcase_02 AC 395 ms
63,556 KB
testcase_03 AC 589 ms
66,916 KB
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 AC 125 ms
55,292 KB
testcase_10 AC 126 ms
55,432 KB
testcase_11 AC 123 ms
55,464 KB
testcase_12 AC 543 ms
68,132 KB
testcase_13 AC 733 ms
77,036 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
    static char[] base = "inabameguru".toCharArray();
    static HashSet<String> exist = new HashSet<>();
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for (int i = 0; i < n; i++) {
		    exist.add(sc.next());
		}
		make(new char[base.length], 0, 0, 0, 0);
		System.out.println("NO");
	}
	
    static void make(char[] arr, int idx, int mask, int bCount, int sCount) {
        if (bCount - sCount > 1) {
            return;
        }
        if (idx >= arr.length) {
            if (!isBoin(arr[arr.length - 1])) {
                return;
            }
            String s = new String(arr);
            if (!exist.contains(s)) {
                System.out.println(s);
                System.exit(0);
            }
        }
        for (int i = 0; i < base.length; i++) {
            if ((mask & (1 << i)) != 0) {
                continue;
            }
            if (i > 0 && !isBoin(arr[idx - 1]) && !isBoin(base[i])) {
                continue;
            }
            arr[idx] = base[i];
            int bNext = 0;
            int sNext = 0;
            if (isBoin(base[i])) {
                bNext++;
            } else {
                sNext++;
            }
            make(arr, idx + 1, mask ^ (1 << i), bCount + bNext, sCount + sNext);
        }
    }
    
    static boolean isBoin(char c) {
        return c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o';
    }
}
0