結果
問題 |
No.204 ゴールデン・ウィーク(2)
|
ユーザー |
![]() |
提出日時 | 2024-10-10 23:34:13 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 28 ms / 1,000 ms |
コード長 | 3,318 bytes |
コンパイル時間 | 954 ms |
コンパイル使用メモリ | 111,344 KB |
実行使用メモリ | 26,724 KB |
最終ジャッジ日時 | 2024-10-10 23:34:17 |
合計ジャッジ時間 | 3,850 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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.
ソースコード
using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("2"); WillReturn.Add("oxxoxxo"); WillReturn.Add("ooooxxo"); //8 //今年のゴールデンウィークです //有給休暇をうまく使って、8連休に出来ます //(現実には、次の日曜日も合わせ9連休です) } else if (InputPattern == "Input2") { WillReturn.Add("5"); WillReturn.Add("ooxxxxx"); WillReturn.Add("ooooooo"); //14 //全部休みにできますね } else if (InputPattern == "Input3") { WillReturn.Add("1"); WillReturn.Add("oxxxxxo"); WillReturn.Add("xoxxxxo"); //3 //1列目の最後と2列目の先頭はつながっていることに注意してください } 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())); } //Console.WriteLine("有給休暇の使い方候補List"); //AnswerKouhoList.ForEach(X => Console.WriteLine(X)); //Console.WriteLine("■■■■■■■■■■■■■■■"); //Console.WriteLine("最大の連休"); 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; } }