結果
| 問題 | 
                            No.233 めぐるはめぐる (3)
                             | 
                    
| コンテスト | |
| ユーザー | 
                             | 
                    
| 提出日時 | 2015-06-27 00:09:51 | 
| 言語 | Python3  (3.13.1 + numpy 2.2.1 + scipy 1.14.1)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 368 ms / 1,000 ms | 
| コード長 | 1,855 bytes | 
| コンパイル時間 | 644 ms | 
| コンパイル使用メモリ | 12,800 KB | 
| 実行使用メモリ | 26,284 KB | 
| 最終ジャッジ日時 | 2024-07-07 19:29:59 | 
| 合計ジャッジ時間 | 4,986 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge2 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 11 | 
ソースコード
import itertools
def read_data():
    N = int(input())
    Ss = [input() for i in range(N)]
    return N, Ss
def solve(N, Ss):
    '''
    n[]b[]m[]g[]r[]
    [] には、母音が必ず必要。
    残りの母音は、任意の位置に挿入可能。
    
    '''
    original = 'inabameguru'
    if N == 0:
        return original
    vowels = [
            ['aa','i','e','u','u'],
            ['a','ai','e','u','u'],
            ['a','ia','e','u','u'],
            ['a','i','ae','u','u'],
            ['a','i','ea','u','u'],
            ['a','i','e','au','u'],
            ['a','i','e','ua','u'],
            ['a','a','ie','u','u'],
            ['a','a','ei','u','u'],
            ['a','a','e','iu','u'],
            ['a','a','e','ui','u'],
            ['a','a','i','eu','u'],
            ['a','a','i','ue','u'],
            ['a','a','i','e','uu'],
            ['a', 'a', 'i', 'e', 'u', 'u']]
    cons = ['n', 'b', 'm', 'g', 'r']
    vowel_perm5 = set()
    for vowel in vowels[:-1]:
        for permutated in itertools.permutations(vowel):
            vowel_perm5.add(permutated)
    vowel_perm6 = set()
    for permutated in itertools.permutations(vowels[-1]):
        vowel_perm6.add(permutated)
    cons_perm = set()
    for permutated in itertools.permutations(cons):
        cons_perm.add(permutated)
    n_max = len(cons_perm) * (len(vowel_perm5) + len(vowel_perm6))
    if N == n_max:
        return 'NO'
    used = set(Ss)
    for con in cons_perm:
        for vowel5 in vowel_perm5:
            handle = ''.join([a + b for a, b in zip(con, vowel5)])
            if handle not in used:
                return handle
        for vowel6 in vowel_perm6:
            handle = vowel6[0] + ''.join([a + b for a, b in zip(con, vowel6[1:])])
            if handle not in used:
                return handle
N, Ss = read_data()
print(solve(N, Ss))