結果
問題 | No.233 めぐるはめぐる (3) |
ユーザー |
![]() |
提出日時 | 2020-05-12 17:34:32 |
言語 | Java (openjdk 23) |
結果 |
RE
|
実行時間 | - |
コード長 | 1,493 bytes |
コンパイル時間 | 2,286 ms |
コンパイル使用メモリ | 78,624 KB |
実行使用メモリ | 73,252 KB |
最終ジャッジ日時 | 2024-09-13 15:58:38 |
合計ジャッジ時間 | 14,707 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 RE * 5 |
ソースコード
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'; } }