結果

問題 No.247 線形計画問題もどき
ユーザー sekiya9311sekiya9311
提出日時 2016-10-25 22:24:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 119 ms / 2,000 ms
コード長 1,458 bytes
コンパイル時間 2,358 ms
コンパイル使用メモリ 107,772 KB
実行使用メモリ 22,884 KB
最終ジャッジ日時 2023-09-21 18:17:15
合計ジャッジ時間 6,356 ms
ジャッジサーバーID
(参考情報)
judge12 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
20,720 KB
testcase_01 AC 59 ms
20,892 KB
testcase_02 AC 119 ms
20,840 KB
testcase_03 AC 60 ms
18,632 KB
testcase_04 AC 59 ms
22,608 KB
testcase_05 AC 59 ms
20,812 KB
testcase_06 AC 58 ms
20,908 KB
testcase_07 AC 63 ms
20,932 KB
testcase_08 AC 60 ms
20,932 KB
testcase_09 AC 58 ms
20,776 KB
testcase_10 AC 60 ms
22,884 KB
testcase_11 AC 59 ms
20,780 KB
testcase_12 AC 60 ms
20,744 KB
testcase_13 AC 60 ms
20,668 KB
testcase_14 AC 59 ms
18,644 KB
testcase_15 AC 59 ms
20,544 KB
testcase_16 AC 59 ms
20,748 KB
testcase_17 AC 66 ms
22,596 KB
testcase_18 AC 61 ms
22,700 KB
testcase_19 AC 78 ms
18,668 KB
testcase_20 AC 89 ms
22,652 KB
testcase_21 AC 62 ms
18,776 KB
testcase_22 AC 63 ms
18,696 KB
testcase_23 AC 62 ms
20,772 KB
testcase_24 AC 89 ms
20,820 KB
testcase_25 AC 81 ms
20,640 KB
testcase_26 AC 64 ms
22,660 KB
testcase_27 AC 66 ms
20,696 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.IO;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;


class Template
{
	static Scanner sc;
	public static void Main(string[] args)
	{
		const int INF = (int)1e9;
		sc = new Scanner();
		int C = sc.nextInt();
		int N = sc.nextInt();
		int[] a = sc.nextIntArray();
		Array.Sort(a);
		Array.Reverse(a);
		int[] dp = new int[C * 2];
		for (int i = 0; i < dp.Length; i++)
		{
			dp[i] = INF;
		}
		//dp[i] : f(...) = iになるxの和の最小値
		dp[0] = 0;
		//while (true)
		{
			for (int i = 0; i < C; i++)
			{
				foreach (var el in a)
				{
					if (i + el <= C && dp[i] != INF)
					{
						dp[i + el] = Math.Min(dp[i + el], dp[i] + 1);
					}
				}
			}
		}
		if (dp[C] == INF)
		{
			dp[C] = -1;
		}
		Console.WriteLine(dp[C]);
	}
}

public class Scanner
{
	public Scanner() { }
	public string next()
	{
		return Console.ReadLine();
	}
	public int nextInt()
	{
		return int.Parse(next());
	}
	public double nextDouble()
	{
		return double.Parse(next());
	}
	public long nextLong()
	{
		return long.Parse(next());
	}
	public string[] nextArray()
	{
		return next().Split(' ');
	}
	public int[] nextIntArray()
	{
		return Array.ConvertAll(nextArray(), e => int.Parse(e));
	}
	public long[] nextLongArray()
	{
		return Array.ConvertAll(nextArray(), e => long.Parse(e));
	}
	public double[] nextDoubleArray()
	{
		return Array.ConvertAll(nextArray(), e => double.Parse(e));
	}
}
0