結果

問題 No.527 ナップサック容量問題
ユーザー 6soukiti296soukiti29
提出日時 2017-06-21 22:59:07
言語 Nim
(2.0.2)
結果
AC  
実行時間 153 ms / 2,000 ms
コード長 886 bytes
コンパイル時間 3,757 ms
コンパイル使用メモリ 69,972 KB
実行使用メモリ 11,256 KB
最終ジャッジ日時 2023-09-12 13:07:59
合計ジャッジ時間 6,916 ms
ジャッジサーバーID
(参考情報)
judge14 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 4 ms
4,380 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 71 ms
6,148 KB
testcase_06 AC 120 ms
10,384 KB
testcase_07 AC 112 ms
9,568 KB
testcase_08 AC 53 ms
5,488 KB
testcase_09 AC 4 ms
4,376 KB
testcase_10 AC 98 ms
10,140 KB
testcase_11 AC 69 ms
8,452 KB
testcase_12 AC 64 ms
6,940 KB
testcase_13 AC 153 ms
11,256 KB
testcase_14 AC 77 ms
6,000 KB
testcase_15 AC 95 ms
8,888 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 60 ms
6,620 KB
testcase_18 AC 71 ms
7,632 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 45 ms
5,560 KB
testcase_21 AC 108 ms
10,340 KB
testcase_22 AC 124 ms
9,220 KB
testcase_23 AC 94 ms
10,492 KB
testcase_24 AC 37 ms
4,376 KB
testcase_25 AC 75 ms
8,920 KB
testcase_26 AC 85 ms
8,536 KB
testcase_27 AC 95 ms
8,504 KB
testcase_28 AC 83 ms
8,424 KB
testcase_29 AC 148 ms
11,064 KB
testcase_30 AC 4 ms
4,376 KB
testcase_31 AC 2 ms
4,380 KB
testcase_32 AC 2 ms
4,380 KB
testcase_33 AC 2 ms
4,376 KB
testcase_34 AC 2 ms
4,376 KB
testcase_35 AC 81 ms
8,232 KB
testcase_36 AC 2 ms
4,376 KB
testcase_37 AC 65 ms
6,940 KB
testcase_38 AC 46 ms
8,112 KB
testcase_39 AC 68 ms
7,652 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sequtils,strutils,algorithm

let N = readline(stdin).parseInt
type
    item = tuple[value : int, weight : int]
var
    nimotu : item
    weights = newSeqWith(1,0)
    A : array[1_000_000,int]
    w2 : seq[int]
for n in 0..<N:
    let L = readline(stdin).split.map(parseInt)
    nimotu = (value : L[0],weight : L[1])
    w2 = @[]
    for w in reversed(weights):
        if A[nimotu.weight + w] == 0:
            w2.add(nimotu.weight + w)
            A[nimotu.weight + w] = nimotu.value + A[w]
        elif A[nimotu.weight + w] < nimotu.value + A[w]:
            A[nimotu.weight + w] = nimotu.value + A[w]
    for wadd in w2:
        weights.insert(wadd,weights.lowerBound(wadd))
let V = readline(stdin).parseInt
var l,r : int
for i,num in A:
    if l == 0 and num == V:
        l = i
    if num > V:
        r = i - 1
        break
echo l
if r > 0:
    echo r
else:
    echo "inf"
0