結果
問題 | No.233 めぐるはめぐる (3) |
ユーザー | uafr_cs |
提出日時 | 2015-08-31 00:31:29 |
言語 | Java21 (openjdk 21) |
結果 |
AC
|
実行時間 | 944 ms / 1,000 ms |
コード長 | 2,822 bytes |
コンパイル時間 | 2,037 ms |
コンパイル使用メモリ | 79,808 KB |
実行使用メモリ | 76,536 KB |
最終ジャッジ日時 | 2024-07-18 15:49:23 |
合計ジャッジ時間 | 16,618 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 876 ms
76,152 KB |
testcase_01 | AC | 837 ms
76,536 KB |
testcase_02 | AC | 819 ms
73,552 KB |
testcase_03 | AC | 848 ms
76,188 KB |
testcase_04 | AC | 890 ms
76,476 KB |
testcase_05 | AC | 944 ms
76,396 KB |
testcase_06 | AC | 904 ms
75,956 KB |
testcase_07 | AC | 888 ms
76,204 KB |
testcase_08 | AC | 885 ms
76,128 KB |
testcase_09 | AC | 596 ms
73,504 KB |
testcase_10 | AC | 641 ms
73,364 KB |
testcase_11 | AC | 659 ms
73,616 KB |
testcase_12 | AC | 883 ms
76,476 KB |
testcase_13 | AC | 906 ms
76,132 KB |
ソースコード
import java.io.BufferedReader; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedList; import java.util.Scanner; import java.util.Set; import java.util.StringTokenizer; import java.util.TreeSet; public class Main { public static boolean is_vowel(char c){ return c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o'; } public static void dfs(final int deep, char[] input, StringBuilder builder, boolean[] used, HashSet<String> result){ final char prev = builder.length() == 0 ? 'i' : builder.charAt(builder.length() - 1); if(deep >= input.length){ //System.out.println(builder); result.add(builder.toString()); return; } int can_use_vovel = 0, can_use_not_vovel = 0; for(int i = 0; i < input.length; i++){ if(!used[i]){ if(is_vowel(input[i])){ can_use_vovel++; }else{ can_use_not_vovel++; } } } if(can_use_vovel < can_use_not_vovel){ return; } for(int next = 0; next < input.length; next++){ if(used[next]){ continue; } if(!is_vowel(prev) && !is_vowel(input[next])){ continue; } if(deep == input.length - 1 && !is_vowel(input[next])){ continue; } used[next] = true; builder.append(input[next]); dfs(deep + 1, input, builder, used, result); builder.deleteCharAt(builder.length() - 1); used[next] = false; } } public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); final String meguru = "inabameguru"; final int N = sc.nextInt(); HashSet<String> result = new HashSet<String>(); dfs(0, meguru.toCharArray(), new StringBuilder(), new boolean[meguru.length()], result); for(int i = 0; i < N; i++){ result.remove(sc.next()); } if(result.isEmpty()){ System.out.println("NO"); }else{ for(String s : result){ System.out.println(s); break; } } } public static class Scanner implements Closeable { private BufferedReader br; private StringTokenizer tok; public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is)); } private void getLine() throws IOException { while (!hasNext()) { tok = new StringTokenizer(br.readLine()); } } private boolean hasNext() { return tok != null && tok.hasMoreTokens(); } public String next() throws IOException { getLine(); return tok.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public void close() throws IOException { br.close(); } } }