結果

問題 No.204 ゴールデン・ウィーク(2)
ユーザー 明智重蔵
提出日時 2015-07-26 16:51:23
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 26 ms / 1,000 ms
コード長 2,711 bytes
コンパイル時間 1,102 ms
コンパイル使用メモリ 108,544 KB
実行使用メモリ 18,560 KB
最終ジャッジ日時 2024-12-24 11:48:52
合計ジャッジ時間 3,598 ms
ジャッジサーバーID
(参考情報)
judge4 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 46
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;

class Program
{
    static string InputPattern = "Input4";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("2");
            WillReturn.Add("oxxoxxo");
            WillReturn.Add("ooooxxo");
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("5");
            WillReturn.Add("ooxxxxx");
            WillReturn.Add("ooooooo");
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("1");
            WillReturn.Add("oxxxxxo");
            WillReturn.Add("xoxxxxo");
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        int D = int.Parse(InputList[0]);
        string DayStr = InputList[1] + InputList[2];

        //前後に有給休暇の日数分の平日を付加
        DayStr = new string('x', D) + DayStr + new string('x', D);
        int UB = DayStr.Length - 1;

        var AnswerKouhoList = new List<string>() { DayStr };
        for (int I = 0; I <= UB; I++) {
            //現在の添字から連続した有給休暇を設定したものが、解候補
            if (I + D - 1 > UB) break;
            if (DayStr[I] != 'x') continue; //平日から開始してない場合

            var wkCharList = new List<char>();

            bool IsSeqHeijitu = true; //現在の添字から連続した平日か?
            for (int J = 0; J <= UB; J++) {
                if (I <= J && J <= I + D - 1) {
                    if (DayStr[J] == 'o') IsSeqHeijitu = false;
                    if (IsSeqHeijitu) wkCharList.Add('o');
                    else wkCharList.Add(DayStr[J]);
                }
                else wkCharList.Add(DayStr[J]);
            }

            AnswerKouhoList.Add(new string(wkCharList.ToArray()));
        }
        //AnswerKouhoList.ForEach(X => Console.WriteLine(X));
        Console.WriteLine(AnswerKouhoList.Max(X => DeriveMaxSeqCnt(X)));
    }

    //String型を引数として、最大のoの連続数を返す
    static int DeriveMaxSeqCnt(string pDayStr)
    {
        int MaxSeqCnt = 0;
        int CurrSeqCnt = 0;

        foreach (char EachChar in pDayStr) {
            if (EachChar == 'o') CurrSeqCnt++; //休日だった場合
            else CurrSeqCnt = 0;//平日だった場合

            if (MaxSeqCnt < CurrSeqCnt)
                MaxSeqCnt = CurrSeqCnt;
        }
        return MaxSeqCnt;
    }
}
0