結果

問題 No.233 めぐるはめぐる (3)
ユーザー htensaihtensai
提出日時 2020-05-12 17:13:59
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,447 bytes
コンパイル時間 2,278 ms
コンパイル使用メモリ 75,144 KB
実行使用メモリ 78,248 KB
最終ジャッジ日時 2023-10-11 16:53:50
合計ジャッジ時間 15,215 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 769 ms
75,860 KB
testcase_01 AC 590 ms
67,596 KB
testcase_02 AC 405 ms
64,188 KB
testcase_03 AC 627 ms
67,832 KB
testcase_04 AC 837 ms
76,808 KB
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 850 ms
77,560 KB
testcase_08 AC 849 ms
75,772 KB
testcase_09 AC 131 ms
57,740 KB
testcase_10 AC 131 ms
56,040 KB
testcase_11 AC 130 ms
53,860 KB
testcase_12 AC 550 ms
67,952 KB
testcase_13 AC 773 ms
76,264 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		HashSet<String> exist = new HashSet<>();
		for (int i = 0; i < n; i++) {
		    exist.add(sc.next());
		}
		StringSet boins = new StringSet("iaaeuu");
		StringSet shiins = new StringSet("nbmgr");
		for (String x : boins.set) {
		    for (String y : shiins.set) {
		        String z = merge(x, y);
		        if (!exist.contains(z)) {
		            System.out.println(z);
		            return;
		        }
		    }
		}
		System.out.println("NO");
	}
	
	static String merge(String boin, String shiin) {
	    StringBuilder sb = new StringBuilder();
	    for (int i = 0; i < boin.length() + shiin.length(); i++) {
	        if (i % 2 == 0) {
	            sb.append(boin.charAt(i / 2));
	        } else {
	            sb.append(shiin.charAt(i / 2));
	        }
	    }
	    return sb.toString();
	}
	
	static class StringSet {
	    char[] base;
	    HashSet<String> set = new HashSet<>();
	    
	    public StringSet(String s) {
	        base = s.toCharArray();
	        make(new char[base.length], 0, 0);
	    }
	    
	    void make(char[] arr, int idx, int mask) {
	        if (idx >= arr.length) {
	            set.add(new String(arr));
	            return;
	        }
	        for (int i = 0; i < base.length; i++) {
	            if ((mask & (1 << i)) != 0) {
	                continue;
	            }
	            arr[idx] = base[i];
	            make(arr, idx + 1, mask ^ (1 << i));
	        }
	    }
	}
	
	static boolean getResult(StringBuilder sb, int left, int right, boolean isLeft) {
	    int idx = -1;
	    char ch = (char)0;
	    while (left >= 0 && right < sb.length()) {
	        if (sb.charAt(left) != sb.charAt(right)) {
	            if (idx >= 0) {
	                return false;
	            }
	            if (isLeft) {
	                idx = left + 1;
	                ch = sb.charAt(right);
	                right++;
	            } else {
	                idx = right;
	                ch = sb.charAt(left);
	                left--;
	            }
	        } else {
	            left--;
	            right++;
	        }
	    }
	    if (idx < 0) {
	        if (isLeft) {
	            idx = 0;
	            ch = sb.charAt(sb.length() - 1);
	        } else {
	            idx = sb.length();
	            ch = sb.charAt(0);
	        }
	    }
	    sb.insert(idx, ch);
	    return true;
	}
}
0