結果

問題 No.385 カップ麺生活
ユーザー AreTrashAreTrash
提出日時 2016-07-01 23:31:55
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,533 bytes
コンパイル時間 3,617 ms
コンパイル使用メモリ 115,972 KB
実行使用メモリ 29,556 KB
最終ジャッジ日時 2024-04-20 06:14:32
合計ジャッジ時間 3,688 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 36 ms
19,456 KB
testcase_01 AC 36 ms
19,200 KB
testcase_02 AC 36 ms
19,328 KB
testcase_03 AC 36 ms
19,328 KB
testcase_04 AC 37 ms
19,456 KB
testcase_05 AC 37 ms
19,456 KB
testcase_06 AC 37 ms
19,712 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 35 ms
19,584 KB
testcase_10 AC 40 ms
19,552 KB
testcase_11 AC 36 ms
19,200 KB
testcase_12 AC 36 ms
19,328 KB
testcase_13 WA -
testcase_14 AC 39 ms
19,712 KB
testcase_15 WA -
testcase_16 AC 37 ms
19,456 KB
testcase_17 AC 40 ms
19,584 KB
testcase_18 WA -
testcase_19 AC 39 ms
19,712 KB
testcase_20 WA -
testcase_21 WA -
testcase_22 AC 40 ms
19,712 KB
testcase_23 WA -
testcase_24 AC 40 ms
19,584 KB
testcase_25 AC 39 ms
19,584 KB
testcase_26 AC 39 ms
19,712 KB
testcase_27 AC 39 ms
19,584 KB
testcase_28 WA -
testcase_29 AC 38 ms
19,456 KB
testcase_30 WA -
testcase_31 AC 36 ms
19,328 KB
testcase_32 AC 38 ms
19,456 KB
testcase_33 WA -
testcase_34 AC 38 ms
19,584 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] = dp[i] + 1;
                    }
                }
            } 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