結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー 14番14番
提出日時 2016-05-03 18:38:27
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 34 ms / 1,000 ms
コード長 4,736 bytes
コンパイル時間 1,200 ms
コンパイル使用メモリ 110,080 KB
実行使用メモリ 19,712 KB
最終ジャッジ日時 2024-06-06 18:45:20
合計ジャッジ時間 3,763 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 34 ms
19,456 KB
testcase_01 AC 31 ms
19,584 KB
testcase_02 AC 33 ms
19,328 KB
testcase_03 AC 32 ms
19,584 KB
testcase_04 AC 32 ms
19,200 KB
testcase_05 AC 32 ms
19,456 KB
testcase_06 AC 34 ms
19,328 KB
testcase_07 AC 34 ms
19,456 KB
testcase_08 AC 33 ms
19,584 KB
testcase_09 AC 33 ms
19,584 KB
testcase_10 AC 34 ms
19,456 KB
testcase_11 AC 32 ms
19,584 KB
testcase_12 AC 32 ms
19,456 KB
testcase_13 AC 31 ms
19,456 KB
testcase_14 AC 32 ms
19,456 KB
testcase_15 AC 31 ms
19,456 KB
testcase_16 AC 31 ms
19,584 KB
testcase_17 AC 30 ms
19,456 KB
testcase_18 AC 30 ms
19,456 KB
testcase_19 AC 31 ms
19,456 KB
testcase_20 AC 30 ms
19,456 KB
testcase_21 AC 30 ms
19,584 KB
testcase_22 AC 30 ms
19,456 KB
testcase_23 AC 32 ms
19,584 KB
testcase_24 AC 31 ms
19,712 KB
testcase_25 AC 32 ms
19,328 KB
testcase_26 AC 31 ms
19,456 KB
testcase_27 AC 32 ms
19,456 KB
testcase_28 AC 33 ms
19,584 KB
testcase_29 AC 34 ms
19,584 KB
testcase_30 AC 32 ms
19,584 KB
testcase_31 AC 31 ms
19,584 KB
testcase_32 AC 33 ms
19,584 KB
testcase_33 AC 31 ms
19,584 KB
testcase_34 AC 34 ms
19,456 KB
testcase_35 AC 30 ms
18,944 KB
testcase_36 AC 31 ms
18,816 KB
testcase_37 AC 32 ms
19,328 KB
testcase_38 AC 32 ms
19,456 KB
testcase_39 AC 31 ms
19,456 KB
testcase_40 AC 31 ms
19,456 KB
testcase_41 AC 31 ms
19,584 KB
testcase_42 AC 30 ms
19,456 KB
testcase_43 AC 31 ms
19,328 KB
testcase_44 AC 32 ms
19,456 KB
testcase_45 AC 31 ms
19,584 KB
testcase_46 AC 31 ms
19,712 KB
testcase_47 AC 32 ms
19,456 KB
testcase_48 AC 33 ms
19,712 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;
using System.Text;
using System.Linq;
 
class Program
{
    public void Proc()
    {
        Reader.IsDebug = false;
        int yukyuCount = int.Parse(Reader.ReadLine());

        StringBuilder sb = new StringBuilder();
        sb.Append(Reader.ReadLine());
        sb.Append(Reader.ReadLine());
        this.input = this.SplitCalendar(sb.ToString());

        List<string> kumiawase = this.GetKumiawase(0, yukyuCount);
        int ans = 0;
        kumiawase.ForEach((a)=>{
           string[] tmp = a.Split('x');
           ans = Math.Max(ans, tmp.Max(b=>b.Length)); 
        });
        Console.WriteLine(ans);
    }
    
    private String[] SplitCalendar(string inpt) {
        List<String> ans = new List<string>();
        int pos = 0;
        for(int i=1; i<inpt.Length; i++) {
            if(inpt[i-1] != inpt[i]) {
                ans.Add(inpt.Substring(pos, i - pos));
                pos = i;
            }
        }
        ans.Add(inpt.Substring(pos, inpt.Length - pos));
        return ans.ToArray();
    }
    
    string[] input ;
    private Dictionary<int, Dictionary<int, List<String>>> dic = new Dictionary<int, Dictionary<int, List<String>>>();
    private List<string> GetKumiawase(int idx, int remainYukyu) {
        if(!dic.ContainsKey(idx)) {
            dic.Add(idx, new Dictionary<int, List<string>>());
        }
        if(dic[idx].ContainsKey(remainYukyu)) {
            return dic[idx][remainYukyu];
        }
        List<string> ans = new List<string>();
        if(idx == input.Length - 1) {
            if(remainYukyu == 0) {
                ans.Add(this.input[idx]);
            } else {
                if(input[idx].StartsWith("o")) {
                    ans.Add(input[idx] + "o".PadLeft(remainYukyu, 'o'));
                } else
                {
                    ans.Add("o".PadLeft(remainYukyu));
                }
            }
        } else
        {
            if(this.input[idx].StartsWith("o")) {
                List<string> tmp = this.GetKumiawase(idx+1, remainYukyu);
                tmp.ForEach(a=>ans.Add(this.input[idx] + a));
                if(idx == 0 && remainYukyu > 0) {
                    tmp = this.GetKumiawase(idx + 1, 0);
                    tmp.ForEach(a=>ans.Add("o".PadLeft(remainYukyu, 'o') + this.input[idx] + a));
                }
            } else
            {
                List <string> tmp = this.GetKumiawase(idx+1, remainYukyu);
                tmp.ForEach(a=>ans.Add(this.input[idx] + a));
                if(remainYukyu > 0) {
                    if(remainYukyu >= this.input[idx].Length) {
                        int len = this.input[idx].Length;
                        if(idx == 0) {
                            len = remainYukyu;
                        }
                        tmp = this.GetKumiawase(idx+1, 0);
                        tmp.ForEach(a=>ans.Add("o".PadLeft(len, 'o') + a));
                    } else
                    {
                        string holiday = "o".PadLeft(remainYukyu, 'o');
                        string buisinessDay = "x".PadLeft(this.input[idx].Length - remainYukyu, 'x');
                        
                        tmp = this.GetKumiawase(idx+1, 0);
                        tmp.ForEach((a)=>{
                            ans.Add(holiday + buisinessDay + a);
                            ans.Add(buisinessDay + holiday + a);
                        });
                    }
                }
            }
        }
        this.dic[idx].Add(remainYukyu, ans);
        return ans;
    }


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


14
ooxxxxx
xxxxxxo

 
";
        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