結果

問題 No.233 めぐるはめぐる (3)
ユーザー uafr_csuafr_cs
提出日時 2015-07-01 18:19:13
言語 Java21
(openjdk 21)
結果
MLE  
実行時間 -
コード長 1,540 bytes
コンパイル時間 3,918 ms
コンパイル使用メモリ 80,832 KB
実行使用メモリ 134,000 KB
最終ジャッジ日時 2023-09-22 04:59:07
合計ジャッジ時間 7,843 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

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.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;
		}
		
		for(int next = 0; next < input.length; next++){
			if(used[next]){ continue; }
			if(!is_vowel(prev) && !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) {
		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());
		}
		
		System.out.println(result.isEmpty() ? "NO" : "YES");
		if(!result.isEmpty()){
			for(String s : result){
				System.out.println(s);
				break;
			}
		}
		
	}
}
0