結果

問題 No.233 めぐるはめぐる (3)
ユーザー nuwasoginuwasogi
提出日時 2015-12-02 05:28:15
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 4,564 bytes
コンパイル時間 3,068 ms
コンパイル使用メモリ 113,464 KB
実行使用メモリ 63,184 KB
最終ジャッジ日時 2023-10-12 08:50:50
合計ジャッジ時間 7,579 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
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 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Meguru_ha_Meguru_CS
{
    class Program
    {
        static void Main(string[] args)
        {
            Solver sol = new Solver();
            sol.Solve();
        }
    }

    class Solver
    {
        int N;
        const int N_MAX = 129600;
        HashSet<string> usedNames; // 使用済み名前
        HashSet<string> constants; // 全子音列
        HashSet<string> vowels; // 全母音列
        const string originalconstant = "nbmgr";
        const string originalvowel = "iaaeuu";

        public void Solve()
        {
            if (N == N_MAX)
            {
                Console.WriteLine("NO");
                return;
            }
            if (N == 0)
            {
                Console.WriteLine("inabameguru");
                return;
            }
            // 各子音列について
            foreach (char[] c in Permutation.Enumurate(originalconstant))
            {
                string sc = new string(c);
                // 各母音列について
                foreach (string sv in vowels)
                {
                    // 各ローマ字読み可能な文字列について
                    foreach (string name in RomanReadable(sc, sv))
                    {
                        if (!usedNames.Contains(name))
                        {
                            Console.WriteLine(name);
                            return;
                        }
                    }
                }
            }
        }

        public Solver()
        {
            N = ri();
            usedNames = new HashSet<string>();
            constants = new HashSet<string>();
            vowels = new HashSet<string>();
            for (int i = 0; i < N; i++)
            {
                string s = rs();
                usedNames.Add(s);
                StringBuilder sb = new StringBuilder(originalvowel.Length);
                foreach (int[] ia in Permutation.Enumurate(Enumerable.Range(0, originalvowel.Length)))
                {
                    for (int j = 0; j < originalvowel.Length; j++)
                    {
                        sb.Append(originalvowel[ia[j]]);
                    }
                    vowels.Add(sb.ToString());
                }
            }
        }
        /* ローマ字読み可能な文字列を返すイテレータ */
        static IEnumerable<string> RomanReadable(string cons, string vows)
        {
            for (int i = 0; i < 6; i++)
            {
                StringBuilder result = new StringBuilder(11);
                for (int j = 0; j < i; j++)
                {
                    result.Append(cons[j]);
                    result.Append(vows[j]);
                }
                result.Append(vows[i]);
                for (int j = i; j < 5; j++)
                {
                    result.Append(cons[j]);
                    result.Append(vows[j + 1]);
                }
                yield return result.ToString();
            }
        }

        static String rs() { return Console.ReadLine(); }
        static int ri() { return int.Parse(Console.ReadLine()); }
        static long rl() { return long.Parse(Console.ReadLine()); }
        static double rd() { return double.Parse(Console.ReadLine()); }
        static String[] rsa() { return Console.ReadLine().Split(' '); }
        static int[] ria() { return Console.ReadLine().Split(' ').Select(e => int.Parse(e)).ToArray(); }
        static long[] rla() { return Console.ReadLine().Split(' ').Select(e => long.Parse(e)).ToArray(); }
        static double[] rda() { return Console.ReadLine().Split(' ').Select(e => double.Parse(e)).ToArray(); }
    }

    static class Permutation
    {
        public static IEnumerable<T[]> Enumurate<T>(IEnumerable<T> nums)
        {
            return _GetPermutations<T>(new List<T>(), nums.ToList());
        }
        static IEnumerable<T[]> _GetPermutations<T>(IEnumerable<T> perm, IEnumerable<T> nums)
        {
            if (nums.Count() == 0)
            {
                yield return perm.ToArray();
            }
            else
            {
                foreach (var n in nums)
                {
                    var result = _GetPermutations<T>(perm.Concat(new T[] { n }), nums.Where(x => x.Equals(n) == false));
                    foreach (var xs in result)
                    {
                        yield return xs.ToArray();
                    }
                }
            }
        }
    }
}
0