結果

問題 No.233 めぐるはめぐる (3)
ユーザー 14番14番
提出日時 2016-05-08 00:03:01
言語 C#(csc)
(csc 3.9.0)
結果
MLE  
実行時間 -
コード長 4,159 bytes
コンパイル時間 1,038 ms
コンパイル使用メモリ 116,308 KB
実行使用メモリ 132,048 KB
最終ジャッジ日時 2024-04-15 13:42:27
合計ジャッジ時間 7,262 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 MLE -
testcase_01 AC 433 ms
119,216 KB
testcase_02 AC 422 ms
117,372 KB
testcase_03 AC 438 ms
122,264 KB
testcase_04 MLE -
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;
 
class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        string targetstr = "inabameguru";
        int inputCount =int.Parse( Reader.ReadLine());
        for (int i=0; i<inputCount; i++) {
            this.NGList.Add(Reader.ReadLine());
        }
        List<char> boin = new List<char>();
        List<char> shiin = new List<char>();
        List<char> boinList = new List<char>( new char[]{'a', 'i','u','e','o'});
        for(int i=0; i<targetstr.Length; i++) {
            char c = targetstr[i];
            if(boinList.Contains(c)) {
                boin.Add(targetstr[i]);
            } else
            {
                shiin.Add(targetstr[i]);
            }
        }
        List<string> list = this.getAns(boin, shiin, true);
        foreach (string newName in list)
        {
            if(!NGList.Contains(newName)) {
                Console.WriteLine(newName);
                break;
            }
        } 
    }
    
    private Dictionary<string, Dictionary<string, Dictionary<bool, List<string>>>> dic = new Dictionary<string, Dictionary<string, Dictionary<bool, List<string>>>>();
    private List<string> getAns(List<char> boin, List<char> shiin, bool isPrevBoin) {
        string keyBoin = string.Join("", boin);
        string keyShiin = string.Join("", shiin);
        if(!dic.ContainsKey(keyBoin)) {
            dic.Add(keyBoin, new Dictionary<string, Dictionary<bool, List<string>>>());
        }
        if(!dic[keyBoin].ContainsKey(keyShiin)) {
            dic[keyBoin].Add(keyShiin,new Dictionary<bool, List<string>>());
        }
        if(dic[keyBoin][keyShiin].ContainsKey(isPrevBoin)) {
            return dic[keyBoin][keyShiin][isPrevBoin];
        }
        List<string> ans = new List<string>();
        
        if(boin.Count == 1 && shiin.Count == 0) {
            ans.Add(boin[0].ToString());
        } else if(boin.Count == 0 && shiin.Count > 0) {
            
        } else if(shiin.Count > boin.Count) {
            
        } else
        {
            for(int i=0; i<boin.Count; i++) {
                List<char> subBoin = new List<char>(boin);
                subBoin.RemoveAt(i);
                List<string> ret = this.getAns(subBoin, shiin, true);
                if(ret.Count > 0) {
                    ret.ForEach(a=>ans.Add(boin[i] + a));
                }
            }
            if(isPrevBoin) {
                for(int i=0; i<shiin.Count; i++) {
                    List<char> subShin = new List<char>(shiin);
                    subShin.RemoveAt(i);
                    List<string> ret = this.getAns(boin, subShin, false);
                    if(ret.Count > 0) {
                        ret.ForEach(a=>ans.Add(shiin[i] + a));
                    }
                }
            }
        }
        this.dic[keyBoin][keyShiin].Add(isPrevBoin, ans);
        return ans;
        
    }    
    private List<string> NGList = new List<string>();


    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"


3
inabameguru
meguruinaba
nemuriugaba


 
";
        private static System.IO.StringReader Sr = null;
        public static string ReadLine()
        {
            if (IsDebug)
            {
                if (Sr == null)
                {
                    Sr = new System.IO.StringReader(PlainInput.Trim());
                }
                return Sr.ReadLine();
            }
            else
            {
                return Console.ReadLine();
            }
        }
        public static int[] GetInt(char delimiter = ' ', bool trim = false)
        {
            string inptStr = ReadLine();
            if (trim)
            {
                inptStr = inptStr.Trim();
            }
            string[] inpt = inptStr.Split(delimiter);
            int[] ret = new int[inpt.Length];
            for (int i = 0; i < inpt.Length; i++)
            {
                ret[i] = int.Parse(inpt[i]);
            }
            return ret;
        }
    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0