結果

問題 No.291 黒い文字列
ユーザー 14番14番
提出日時 2016-05-15 02:11:33
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 4,237 bytes
コンパイル時間 989 ms
コンパイル使用メモリ 113,704 KB
実行使用メモリ 38,664 KB
最終ジャッジ日時 2024-04-15 21:40:39
合計ジャッジ時間 5,247 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 24 ms
24,192 KB
testcase_01 AC 24 ms
18,432 KB
testcase_02 AC 28 ms
18,944 KB
testcase_03 AC 25 ms
18,816 KB
testcase_04 AC 24 ms
18,560 KB
testcase_05 AC 24 ms
18,304 KB
testcase_06 AC 24 ms
18,432 KB
testcase_07 AC 29 ms
18,944 KB
testcase_08 AC 29 ms
19,456 KB
testcase_09 AC 23 ms
18,560 KB
testcase_10 AC 25 ms
18,688 KB
testcase_11 AC 24 ms
18,560 KB
testcase_12 AC 127 ms
23,040 KB
testcase_13 AC 25 ms
18,944 KB
testcase_14 AC 25 ms
18,688 KB
testcase_15 AC 29 ms
19,328 KB
testcase_16 TLE -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;
using System.Linq;

class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        string inpt = Reader.ReadLine();
        int ans = this.GetAns(inpt, 0, new List<string>());
        Console.WriteLine(ans);

    }


    private int GetAns(string inpt, int idx, List<string> items)
    {
        if (inpt.Count(a => a == '?') == 0)
        {
            return Count(inpt);
        }
        if (inpt.Count(a => a != '?') == 0)
        {
            return inpt.Length / this.target.Length;
        }
        for (int i = idx; i < inpt.Length; i++)
        {
            if (inpt[i] == '?')
            {
                string[] splt = inpt.Split('?');
                string prt1 = splt[0];
                string prt2 = string.Join("?", splt.Skip(1).ToArray());
                List<string> subItems = new List<string>(items);
                int ans = 0;
                if (items.Count < inpt.Length / target.Length)
                {
                    subItems.Add("K");
                    ans = this.GetAns(prt1 + "K" + prt2, idx + 1, subItems);
                }
                for (int j = 1; j < target.Length; j++)
                {
                    string str = items.FirstOrDefault(a => a.Length == j);
                    if (str != null)
                    {
                        subItems = new List<string>(items);
                        int ind = items.IndexOf(str);
                        subItems[ind] += target[j];
                        ans = Math.Max(ans, this.GetAns(prt1 + target[j] + prt2, idx + 1, subItems));
                    }
                }
                return ans;

            }
            else
            {
                
                for (int j = 0; j < target.Length; j++)
                {
                    if (inpt[i] == target[j])
                    {
                        
                        if (j == 0)
                        {
                            items.Add(target[0].ToString());
                        }
                        else
                        {
                            string str = items.FirstOrDefault(a => a.Length == j);
                            if (str != null)
                            {
                                int ind = items.IndexOf(str);
                                items[ind] += target[j];
                            }
                        }
                        break;
                    } 
                }
            }
        }
        return 0;
    }

    private char[] target = new char[] { 'K', 'U', 'R', 'O', 'I' };

    private int Count(string inpt)
    {
        List<string> tmp = new List<string>();
        for (int i = 0; i < inpt.Length; i++)
        {
            for (int j = 0; j < target.Length; j++)
            {
                if (inpt[i] == target[j])
                {
                    if (j == 0)
                    {
                        tmp.Add(target[0].ToString());
                    }
                    else
                    {
                        string key = tmp.FirstOrDefault(a => a.Length == j);
                        if (key != null)
                        {
                            int idx = tmp.IndexOf(key);
                            tmp[idx] += target[j];
                        }
                    }
                    break;
                }
            }
        }
        return tmp.Count(a => a.Length == target.Length);

    }



    public class Reader
    {
        public static bool IsDebug = true;
        private static String PlainInput = @"
 
???K??O??U????R???I?R???


 
";
        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();
            }
        }

    }
    static void Main()
    {
        Program prg = new Program();
        prg.Proc();
    }
}
0