結果

問題 No.385 カップ麺生活
ユーザー AreTrashAreTrash
提出日時 2016-07-01 23:37:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 42 ms / 2,000 ms
コード長 2,554 bytes
コンパイル時間 991 ms
コンパイル使用メモリ 118,580 KB
実行使用メモリ 27,684 KB
最終ジャッジ日時 2024-04-15 07:28:12
合計ジャッジ時間 3,346 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
25,388 KB
testcase_01 AC 37 ms
25,756 KB
testcase_02 AC 37 ms
25,572 KB
testcase_03 AC 37 ms
27,684 KB
testcase_04 AC 37 ms
25,312 KB
testcase_05 AC 38 ms
27,476 KB
testcase_06 AC 38 ms
27,476 KB
testcase_07 AC 38 ms
25,444 KB
testcase_08 AC 37 ms
25,824 KB
testcase_09 AC 35 ms
27,476 KB
testcase_10 AC 40 ms
25,444 KB
testcase_11 AC 36 ms
27,656 KB
testcase_12 AC 37 ms
25,696 KB
testcase_13 AC 38 ms
27,608 KB
testcase_14 AC 42 ms
25,808 KB
testcase_15 AC 38 ms
25,648 KB
testcase_16 AC 38 ms
25,776 KB
testcase_17 AC 39 ms
25,644 KB
testcase_18 AC 37 ms
25,440 KB
testcase_19 AC 38 ms
25,444 KB
testcase_20 AC 38 ms
25,704 KB
testcase_21 AC 38 ms
25,696 KB
testcase_22 AC 38 ms
23,476 KB
testcase_23 AC 39 ms
25,696 KB
testcase_24 AC 38 ms
25,308 KB
testcase_25 AC 36 ms
25,648 KB
testcase_26 AC 36 ms
25,520 KB
testcase_27 AC 39 ms
27,480 KB
testcase_28 AC 39 ms
25,660 KB
testcase_29 AC 37 ms
25,776 KB
testcase_30 AC 38 ms
27,680 KB
testcase_31 AC 38 ms
27,548 KB
testcase_32 AC 37 ms
25,444 KB
testcase_33 AC 39 ms
27,484 KB
testcase_34 AC 38 ms
27,604 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.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;
        }
    }
}
0