結果

問題 No.247 線形計画問題もどき
ユーザー mban
提出日時 2017-07-15 07:12:51
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 81 ms / 2,000 ms
コード長 1,084 bytes
コンパイル時間 920 ms
コンパイル使用メモリ 116,596 KB
実行使用メモリ 27,176 KB
最終ジャッジ日時 2024-07-07 12:08:36
合計ジャッジ時間 2,846 ms
ジャッジサーバーID
(参考情報)
judge5 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 23
権限があれば一括ダウンロードができます
コンパイルメッセージ
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