結果
問題 |
No.233 めぐるはめぐる (3)
|
ユーザー |
|
提出日時 | 2015-07-21 02:33:14 |
言語 | Java (openjdk 23) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 1,663 bytes |
コンパイル時間 | 1,930 ms |
コンパイル使用メモリ | 77,868 KB |
実行使用メモリ | 87,080 KB |
最終ジャッジ日時 | 2024-07-08 11:27:38 |
合計ジャッジ時間 | 13,713 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 6 TLE * 5 |
ソースコード
import java.util.*; public class Main { static HashSet<String> set; static final char[] moji = {'i', 'n', 'a', 'b', 'a', 'm', 'e', 'g', 'u', 'r', 'u'};//11moji static final char[] now = new char[11]; static int used = 0; static int current = 0; static void func(boolean prevNotVowel) { if (current == 11) { if (!set.contains(new String(now))) { System.out.println(now); System.exit(0); } else { return; } } // 子音を使いきった場合(構成できない) if ((used & 0b10101010101) == 0b10101010101) { return; } int step = 1; // 子音の後は、母音しか選べないのでうまいこと2つとばしになっている。 if (prevNotVowel) { step = 2; } for (int i = 0; i < 11; i += step) { final int bit = 1 << i; if ((used & bit) > 0) { continue; } // 選んだものが子音じゃないか判定 boolean isNotVowel = (bit & 0b01010101010) > 0; now[current] = moji[i]; used |= bit; current++; func(isNotVowel); current--; //選択したビットを解除する used &= ~bit; } } public static void main(String[] args) { Scanner sc = new Scanner(System.in); int N = sc.nextInt(); set = new HashSet<>(N); for (int i = 0; i < N; i++) set.add(sc.next()); func(false); System.out.println("NO"); } }