結果

問題 No.247 線形計画問題もどき
ユーザー mbanmban
提出日時 2017-07-15 07:12:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 112 ms / 2,000 ms
コード長 1,084 bytes
コンパイル時間 4,652 ms
コンパイル使用メモリ 107,452 KB
実行使用メモリ 24,000 KB
最終ジャッジ日時 2023-09-21 18:32:36
合計ジャッジ時間 7,006 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
19,548 KB
testcase_01 AC 60 ms
21,728 KB
testcase_02 AC 112 ms
21,900 KB
testcase_03 AC 60 ms
23,680 KB
testcase_04 AC 61 ms
23,644 KB
testcase_05 AC 61 ms
23,772 KB
testcase_06 AC 59 ms
19,636 KB
testcase_07 AC 62 ms
24,000 KB
testcase_08 AC 63 ms
21,896 KB
testcase_09 AC 61 ms
21,648 KB
testcase_10 AC 62 ms
19,844 KB
testcase_11 AC 60 ms
23,644 KB
testcase_12 AC 61 ms
21,708 KB
testcase_13 AC 61 ms
21,728 KB
testcase_14 AC 61 ms
21,848 KB
testcase_15 AC 60 ms
21,588 KB
testcase_16 AC 61 ms
19,672 KB
testcase_17 AC 68 ms
21,660 KB
testcase_18 AC 63 ms
23,696 KB
testcase_19 AC 70 ms
21,672 KB
testcase_20 AC 89 ms
23,872 KB
testcase_21 AC 61 ms
21,716 KB
testcase_22 AC 62 ms
23,756 KB
testcase_23 AC 62 ms
23,748 KB
testcase_24 AC 87 ms
23,896 KB
testcase_25 AC 80 ms
19,752 KB
testcase_26 AC 62 ms
21,656 KB
testcase_27 AC 62 ms
23,732 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;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{
    static void Main()
    {
        new Magatro().Solve();
    }
}

class Magatro
{
    private int C;
    private int N;
    private int[] A;
    private void Scan()
    {
        C = int.Parse(Console.ReadLine());
        N = int.Parse(Console.ReadLine());
        A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    }

    public void Solve()
    {
        Scan();
        var cost = (new int[C + 1]).Select(i => int.MaxValue).ToArray();
        cost[0] = 0;
        for (int i = 0; i <= C; i++)
        {
            if (cost[i] == int.MaxValue) continue;

            foreach (int j in A)
            {
                if (i + j <= C)
                {
                    cost[i + j] = Math.Min(cost[i + j], cost[i] + 1);
                }
            }
        }
        Console.WriteLine(cost[C] == int.MaxValue ? -1 : cost[C]);

    }
}
0