結果
問題 | No.385 カップ麺生活 |
ユーザー |
![]() |
提出日時 | 2016-07-01 23:37:04 |
言語 | C#(csc) (csc 3.9.0) |
結果 |
AC
|
実行時間 | 35 ms / 2,000 ms |
コード長 | 2,554 bytes |
コンパイル時間 | 830 ms |
コンパイル使用メモリ | 116,272 KB |
実行使用メモリ | 27,856 KB |
最終ジャッジ日時 | 2024-10-04 22:28:51 |
合計ジャッジ時間 | 2,901 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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; namespace No385{ public class Program{ public static void Main(string[] args){ var sr = new StreamReader(); //--------------------------------- var M = sr.Next<int>(); var N = sr.Next<int>(); var cn = sr.Next<int>(N); var pl = new List<int>(); if(M > 1) { var nl = Enumerable.Range(2, M - 1).ToList(); var sqrt = (int)Math.Sqrt(M); while(nl[0] <= sqrt) { var prime = nl[0]; pl.Add(prime); nl.RemoveAll(x => x % prime == 0); } pl.AddRange(nl); } var dp = new int[M + 1]; dp[M] = 1; var tmp = new []{1}; do{ tmp = dp.ToArray(); foreach(var c in cn.OrderByDescending(x => x)){ for(var i = M; i >= c; i--){ if(dp[i] >= 1) dp[i - c] = Math.Max(dp[i] + 1, dp[i - c]); } } } while(!dp.SequenceEqual(tmp)); var res = 0; foreach(var p in pl){ if(dp[p] != 0) res += dp[p] - 1; } res += M / cn.Min(); Console.WriteLine(res); //Console.WriteLine(string.Join(" ", dp)); //--------------------------------- } } public class StreamReader{ private readonly char[] _c = {' '}; private int _index = -1; private string[] _input = new string[0]; public T Next<T>(){ if(_index == _input.Length - 1){ _index = -1; while(true){ string rl = Console.ReadLine(); if(rl == null){ if(typeof(T).IsClass) return default(T); return (T)typeof(T).GetField("MinValue").GetValue(null); } if(rl != ""){ _input = rl.Split(_c, StringSplitOptions.RemoveEmptyEntries); break; } } } return (T)Convert.ChangeType(_input[++_index], typeof(T), System.Globalization.CultureInfo.InvariantCulture); } public T[] Next<T>(int x){ var ret = new T[x]; for(var i = 0; i < x; ++i) ret[i] = Next<T>(); return ret; } } }