結果

問題 No.233 めぐるはめぐる (3)
ユーザー ぴろずぴろず
提出日時 2015-06-26 23:00:00
言語 Java21
(openjdk 21)
結果
TLE  
(最新)
AC  
(最初)
実行時間 -
コード長 1,294 bytes
コンパイル時間 3,642 ms
コンパイル使用メモリ 74,636 KB
実行使用メモリ 87,316 KB
最終ジャッジ日時 2023-09-22 01:27:13
合計ジャッジ時間 24,451 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 TLE -
testcase_02 AC 988 ms
81,496 KB
testcase_03 TLE -
testcase_04 TLE -
testcase_05 TLE -
testcase_06 TLE -
testcase_07 TLE -
testcase_08 TLE -
testcase_09 AC 822 ms
71,356 KB
testcase_10 AC 862 ms
70,812 KB
testcase_11 AC 803 ms
70,888 KB
testcase_12 TLE -
testcase_13 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

package no233;

import java.util.Arrays;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		char[] p = "inabameguru".toCharArray();
		Arrays.sort(p);
		int l = p.length;
		HashSet<String> anagram = new HashSet<>();
		LOOP: do {
			if (!isBoin(p[l-1])) {
				continue;
			}
			boolean siin = false;
			for(int i=0;i<l;i++) {
				if (isBoin(p[i])) {
					siin = false;
				}else{
					if (siin) {
						continue LOOP;
					}
					siin = true;
				}
			}
			anagram.add(new String(p));
		} while(nextPermutation(p));

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0;i<n;i++) {
			anagram.remove(sc.next());
		}
		if (anagram.isEmpty()) {
			System.out.println("NO");
		}else{
			System.out.println(anagram.iterator().next());
		}

	}
	static boolean isBoin(char c) {
		return c == 'a' || c == 'i' || c == 'u' || c == 'e';
	}
	static boolean nextPermutation(char[] p) {
		for(int a=p.length-2;a>=0;--a) {
			if(p[a]<p[a+1]) {
				for(int b=p.length-1;;--b) {
					if(p[b]>p[a]) {
						char t = p[a];
						p[a] = p[b];
						p[b] = t;
						for(++a, b=p.length-1;a<b;++a,--b) {
							t = p[a];
							p[a] = p[b];
							p[b] = t;
						}
						return true;
					}
				}
			}
		}
		return false;
	}
}
0