結果

問題 No.527 ナップサック容量問題
ユーザー muz_808muz_808
提出日時 2017-06-10 00:07:40
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 2,505 bytes
コンパイル時間 891 ms
コンパイル使用メモリ 110,848 KB
実行使用メモリ 65,408 KB
最終ジャッジ日時 2023-10-24 03:39:06
合計ジャッジ時間 7,795 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 137 ms
65,352 KB
testcase_01 AC 138 ms
65,352 KB
testcase_02 AC 138 ms
65,364 KB
testcase_03 WA -
testcase_04 AC 137 ms
65,352 KB
testcase_05 AC 137 ms
65,364 KB
testcase_06 AC 138 ms
65,364 KB
testcase_07 WA -
testcase_08 AC 138 ms
65,364 KB
testcase_09 AC 138 ms
65,364 KB
testcase_10 WA -
testcase_11 AC 138 ms
65,364 KB
testcase_12 AC 137 ms
65,364 KB
testcase_13 AC 137 ms
65,364 KB
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 WA -
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 AC 138 ms
65,352 KB
testcase_26 WA -
testcase_27 WA -
testcase_28 AC 137 ms
65,352 KB
testcase_29 WA -
testcase_30 AC 137 ms
65,364 KB
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 WA -
testcase_36 AC 137 ms
65,352 KB
testcase_37 WA -
testcase_38 WA -
testcase_39 WA -
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Text;
using System.Linq;
using System.Collections.Generic;

class Program
{
    private static readonly Scanner sc = new Scanner();
    static void Main(string[] args)
    {
        int n = sc.Int;
        int[] vn = new int[101];
        int[] wn = new int[101];
        for (int i = 1; i <= n; i++)
        {
            vn[i] = sc.Int;
            wn[i] = sc.Int;
        }
        int v = sc.Int;

        int[][] dp = new int[101][];
        for (int i = 0; i <= 100; i++)
            dp[i] = new int[100001];
        for (int i = 1; i <= 100; i++)
        {
            for (int j = 1; j <= 100000; j++)
            {
                if (j < vn[i])
                    dp[i][j] = dp[i - 1][j];
                else
                    
                    dp[i][j] = Math.Max(dp[i - 1][j], dp[i - 1][j - vn[i]] + wn[i]);
            }
        }

        if (dp[n][v] == 0)
        {
            int minw = 1000000000;
            for (int i = 1; i <= n; i++)
                minw = Math.Min(minw, wn[i]);
            Console.WriteLine(1);
            Console.WriteLine(minw-1);
        }
        else
        {
            Console.WriteLine(dp[n][v]);
            if (dp[n][v] == dp[n][100000])
            {
                Console.WriteLine("inf");
            }
            else
            {
                for (int i = 0; i < 100000; i++)
                {
                    if (dp[n][v] < dp[n][i])
                    {
                        Console.WriteLine(dp[n][i]-1);
                        break;
                    }
                }
            } 
        }
    }
}

class Scanner
{
    private string[] _str = new string[0];
    private int _i;

    public string Line { get { return Console.ReadLine(); } }

    public string Str
    {
        get
        {
            if (_i >= _str.Length)
            {
                _str = Line.Split(' ');
                _i = 0;
            }
            return _str[_i++];
        }
    }

    public string[] StrArr { get { return Line.Split(' '); } }
    public int Int { get { return int.Parse(Str); } }
    public int[] IntArr { get { return Line.Split(' ').Select(int.Parse).ToArray(); } }
    public long Long { get { return long.Parse(Str); } }
    public long[] LongArr { get { return Line.Split(' ').Select(long.Parse).ToArray(); } }
    public double Double { get { return double.Parse(Str); } }
    public double[] DoubleArr { get { return Line.Split(' ').Select(double.Parse).ToArray(); } }
}
0