結果
問題 |
No.385 カップ麺生活
|
ユーザー |
![]() |
提出日時 | 2016-07-03 11:10:22 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 200 ms / 2,000 ms |
コード長 | 2,976 bytes |
コンパイル時間 | 1,062 ms |
コンパイル使用メモリ | 112,048 KB |
実行使用メモリ | 33,656 KB |
最終ジャッジ日時 | 2024-10-04 22:38:12 |
合計ジャッジ時間 | 4,589 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 32 |
コンパイルメッセージ
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; //No.385 カップ麺生活 class Program { static string InputPattern = "InputX"; static List<string> GetInputList() { var WillReturn = new List<string>(); if (InputPattern == "Input1") { WillReturn.Add("100"); WillReturn.Add("2"); WillReturn.Add("47 50"); //5 } else if (InputPattern == "Input2") { WillReturn.Add("500"); WillReturn.Add("5"); WillReturn.Add("111 222 333 444 555"); //8 } else if (InputPattern == "Input3") { WillReturn.Add("2447"); WillReturn.Add("3"); WillReturn.Add("9 6 10"); //79842 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { List<string> InputList = GetInputList(); int M = int.Parse(InputList[0]); Eratosthenes(M); int[] CArr = InputList[2].Split(' ').Select(X => int.Parse(X)).ToArray(); Array.Sort(CArr); //昇順にソートしておく //最大購入数[残金]なDP表 var DPArr = new Nullable<int>[M + 1]; DPArr[M] = 0; foreach (int EachCost in CArr) { for (int I = M; 0 <= I; I--) { if (DPArr[I].HasValue == false) continue; int NewInd = I - EachCost; if (NewInd < 0) break; int NewVal = DPArr[I].Value + 1; if (DPArr[NewInd].HasValue == false || DPArr[NewInd].Value < NewVal) { DPArr[NewInd] = NewVal; } } } int Answer = 0; //残金が素数の購入数を集計 for (int I = 0; I <= M; I++) { if (DPArr[I].HasValue == false) continue; if (SosuuArr.Contains(I) == false) continue; Answer += DPArr[I].Value; } //最大の購入数を加算 Answer += DPArr.Max(X => X ?? 0); Console.WriteLine(Answer); } static int[] SosuuArr; //エラトステネスの篩 static void Eratosthenes(int pJyougen) { var CheckArr = new System.Collections.BitArray(pJyougen + 1); for (int I = 2; I <= CheckArr.Count - 1; I++) { CheckArr[I] = true; } for (int I = 2; I <= CheckArr.Count - 1; I++) { if (I != 2 && I % 2 == 0) continue; if (CheckArr[I]) { for (int J = I * 2; J <= CheckArr.Count - 1; J += I) { CheckArr[J] = false; } } } var SosuuList = new List<int>(); for (int I = 2; I <= CheckArr.Count - 1; I++) if (CheckArr[I]) SosuuList.Add(I); SosuuArr = SosuuList.ToArray(); } }