結果

問題 No.385 カップ麺生活
ユーザー AreTrashAreTrash
提出日時 2016-07-01 23:37:04
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 71 ms / 2,000 ms
コード長 2,554 bytes
コンパイル時間 2,652 ms
コンパイル使用メモリ 111,252 KB
実行使用メモリ 24,036 KB
最終ジャッジ日時 2023-07-27 20:48:04
合計ジャッジ時間 6,468 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 67 ms
21,804 KB
testcase_01 AC 66 ms
21,800 KB
testcase_02 AC 68 ms
23,932 KB
testcase_03 AC 68 ms
21,836 KB
testcase_04 AC 68 ms
21,704 KB
testcase_05 AC 68 ms
22,012 KB
testcase_06 AC 69 ms
23,776 KB
testcase_07 AC 69 ms
21,912 KB
testcase_08 AC 68 ms
21,904 KB
testcase_09 AC 64 ms
21,952 KB
testcase_10 AC 71 ms
21,920 KB
testcase_11 AC 65 ms
23,948 KB
testcase_12 AC 67 ms
19,740 KB
testcase_13 AC 67 ms
24,036 KB
testcase_14 AC 70 ms
24,008 KB
testcase_15 AC 69 ms
23,840 KB
testcase_16 AC 67 ms
21,800 KB
testcase_17 AC 69 ms
22,000 KB
testcase_18 AC 67 ms
22,012 KB
testcase_19 AC 68 ms
21,944 KB
testcase_20 AC 69 ms
21,748 KB
testcase_21 AC 69 ms
19,856 KB
testcase_22 AC 69 ms
21,892 KB
testcase_23 AC 69 ms
21,916 KB
testcase_24 AC 70 ms
21,908 KB
testcase_25 AC 68 ms
21,740 KB
testcase_26 AC 68 ms
21,952 KB
testcase_27 AC 69 ms
21,804 KB
testcase_28 AC 70 ms
23,832 KB
testcase_29 AC 69 ms
21,748 KB
testcase_30 AC 70 ms
23,952 KB
testcase_31 AC 71 ms
23,852 KB
testcase_32 AC 69 ms
21,912 KB
testcase_33 AC 70 ms
23,784 KB
testcase_34 AC 68 ms
21,944 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