結果
問題 | No.233 めぐるはめぐる (3) |
ユーザー | Grenache |
提出日時 | 2015-06-26 23:46:45 |
言語 | Java21 (openjdk 21) |
結果 |
TLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 2,231 bytes |
コンパイル時間 | 4,156 ms |
コンパイル使用メモリ | 79,532 KB |
実行使用メモリ | 85,428 KB |
最終ジャッジ日時 | 2023-09-22 01:49:12 |
合計ジャッジ時間 | 16,193 ms |
ジャッジサーバーID (参考情報) |
judge14 / judge11 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 696 ms
75,668 KB |
testcase_01 | AC | 545 ms
68,396 KB |
testcase_02 | AC | 382 ms
63,532 KB |
testcase_03 | AC | 579 ms
68,356 KB |
testcase_04 | TLE | - |
testcase_05 | TLE | - |
testcase_06 | TLE | - |
testcase_07 | TLE | - |
testcase_08 | TLE | - |
testcase_09 | AC | 118 ms
55,220 KB |
testcase_10 | AC | 118 ms
55,448 KB |
testcase_11 | AC | 118 ms
55,628 KB |
testcase_12 | AC | 505 ms
68,524 KB |
testcase_13 | AC | 708 ms
75,172 KB |
ソースコード
import java.util.HashSet; import java.util.Scanner; import java.util.Set; public class Main_yukicoder233 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); hs = new HashSet<String>(); for (int i = 0; i < n; i++) { String s = sc.next(); hs.add(s); } used = new boolean[si.length]; perm = new int[si.length]; permutation(0, si.length); System.out.println("NO"); sc.close(); } static Set<String> hs; static char[] si = {'n', 'b', 'm', 'g', 'r'}; static char[] bo = {'i', 'a', 'a', 'e', 'u', 'u'}; static boolean[] used; static int[] perm; static boolean[] used2; static int[] perm2; // {0, 1, 2, 3, ...., n - 1}の並び替えn!通りを生成する static void permutation(int pos, int n) { if (pos == n) { used2 = new boolean[bo.length]; perm2 = new int[bo.length]; permutation2(0, bo.length); return; } // perm[]のpos番目を0~n-1のどれにするかのループ for (int i = 0; i < n; i++) { if (!used[i]) { perm[pos] = i; // iを使ったのでフラグをtrue used[i] = true; permutation(pos + 1, n); // 戻ってきたらフラグを戻す used[i] = false; } } return; } // {0, 1, 2, 3, ...., n - 1}の並び替えn!通りを生成する static void permutation2(int pos, int n) { if (pos == n) { // perm[] に対する操作 StringBuilder sb = new StringBuilder(); for (int i = 0; i < si.length; i++) { sb.append(si[perm[i]]); sb.append(bo[perm2[i]]); } for (int i = 0; i < si.length; i++) { StringBuilder tmp = new StringBuilder(sb); tmp.insert(i * 2, bo[perm2[bo.length - 1]]); if (!hs.contains(tmp.toString())) { System.out.println(tmp); System.exit(0); } } return; } // perm[]のpos番目を0~n-1のどれにするかのループ for (int i = 0; i < n; i++) { if (!used2[i]) { perm2[pos] = i; // iを使ったのでフラグをtrue used2[i] = true; permutation2(pos + 1, n); // 戻ってきたらフラグを戻す used2[i] = false; } } return; } }