結果

問題 No.233 めぐるはめぐる (3)
ユーザー 14番14番
提出日時 2016-05-08 00:29:37
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 4,506 bytes
コンパイル時間 1,021 ms
コンパイル使用メモリ 117,456 KB
実行使用メモリ 127,880 KB
最終ジャッジ日時 2024-04-15 13:42:36
合計ジャッジ時間 8,067 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 61 ms
33,424 KB
testcase_02 AC 43 ms
26,868 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 32 ms
26,456 KB
testcase_10 AC 32 ms
26,344 KB
testcase_11 AC 31 ms
24,144 KB
testcase_12 AC 62 ms
35,356 KB
testcase_13 AC 75 ms
33,816 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
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, string.Empty);
    }
    
    private bool MustQuit = false;
    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 totyu) {
        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(MustQuit) {
            return ans;
        }
        
        if(boin.Count == 1 && shiin.Count == 0) {
            string ret = totyu + boin[0];
            if(!NGList.Contains(ret)) {
                Console.WriteLine(ret);
                MustQuit = true;
                return ans;
            }
            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, totyu + boin[i]);
                if(ret.Count > 0) {
                    ret.ForEach(a=>ans.Add(boin[i] + a));
                }
                if(MustQuit) {
                    return ans;
                }
            }
            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, totyu +shiin[i]);
                    if(ret.Count > 0) {
                        ret.ForEach(a=>ans.Add(shiin[i] + a));
                    }
                    if(MustQuit) {
                        return ans;
                    }
                }
            }
        }
        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