結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー 14番14番
提出日時 2016-05-03 18:38:27
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 89 ms / 1,000 ms
コード長 4,736 bytes
コンパイル時間 2,425 ms
コンパイル使用メモリ 111,092 KB
実行使用メモリ 24,404 KB
最終ジャッジ日時 2023-08-25 23:49:18
合計ジャッジ時間 8,489 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 88 ms
24,296 KB
testcase_01 AC 87 ms
22,264 KB
testcase_02 AC 88 ms
22,412 KB
testcase_03 AC 87 ms
22,308 KB
testcase_04 AC 87 ms
24,300 KB
testcase_05 AC 87 ms
24,316 KB
testcase_06 AC 86 ms
22,368 KB
testcase_07 AC 87 ms
22,268 KB
testcase_08 AC 86 ms
24,236 KB
testcase_09 AC 88 ms
22,260 KB
testcase_10 AC 88 ms
24,348 KB
testcase_11 AC 88 ms
22,372 KB
testcase_12 AC 87 ms
22,356 KB
testcase_13 AC 86 ms
22,488 KB
testcase_14 AC 87 ms
22,252 KB
testcase_15 AC 88 ms
24,344 KB
testcase_16 AC 88 ms
24,212 KB
testcase_17 AC 88 ms
22,212 KB
testcase_18 AC 87 ms
22,292 KB
testcase_19 AC 89 ms
24,220 KB
testcase_20 AC 88 ms
22,372 KB
testcase_21 AC 87 ms
22,240 KB
testcase_22 AC 86 ms
22,264 KB
testcase_23 AC 88 ms
22,452 KB
testcase_24 AC 88 ms
22,244 KB
testcase_25 AC 88 ms
24,404 KB
testcase_26 AC 87 ms
22,500 KB
testcase_27 AC 87 ms
22,284 KB
testcase_28 AC 89 ms
22,268 KB
testcase_29 AC 88 ms
24,204 KB
testcase_30 AC 89 ms
22,304 KB
testcase_31 AC 87 ms
22,308 KB
testcase_32 AC 86 ms
22,512 KB
testcase_33 AC 85 ms
22,252 KB
testcase_34 AC 89 ms
24,348 KB
testcase_35 AC 64 ms
19,440 KB
testcase_36 AC 65 ms
21,580 KB
testcase_37 AC 88 ms
20,264 KB
testcase_38 AC 88 ms
24,260 KB
testcase_39 AC 87 ms
24,208 KB
testcase_40 AC 87 ms
24,276 KB
testcase_41 AC 87 ms
22,576 KB
testcase_42 AC 86 ms
24,208 KB
testcase_43 AC 86 ms
22,296 KB
testcase_44 AC 86 ms
20,068 KB
testcase_45 AC 87 ms
22,296 KB
testcase_46 AC 88 ms
20,404 KB
testcase_47 AC 88 ms
22,356 KB
testcase_48 AC 89 ms
22,292 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