結果

問題 No.1861 Required Number
ユーザー ygd.ygd.
提出日時 2022-03-04 22:25:39
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 1,379 bytes
コンパイル時間 416 ms
コンパイル使用メモリ 86,928 KB
実行使用メモリ 218,996 KB
最終ジャッジ日時 2023-09-26 03:43:59
合計ジャッジ時間 16,305 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 70 ms
71,264 KB
testcase_01 AC 75 ms
75,420 KB
testcase_02 AC 73 ms
71,424 KB
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 77 ms
75,444 KB
testcase_08 WA -
testcase_09 AC 77 ms
75,480 KB
testcase_10 RE -
testcase_11 RE -
testcase_12 AC 79 ms
75,616 KB
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 AC 75 ms
75,484 KB
testcase_17 RE -
testcase_18 RE -
testcase_19 RE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
testcase_26 RE -
testcase_27 RE -
testcase_28 RE -
testcase_29 RE -
testcase_30 RE -
testcase_31 RE -
testcase_32 RE -
testcase_33 RE -
testcase_34 RE -
testcase_35 RE -
testcase_36 RE -
testcase_37 RE -
testcase_38 RE -
testcase_39 RE -
testcase_40 RE -
testcase_41 RE -
testcase_42 RE -
testcase_43 RE -
testcase_44 WA -
04_evil_1.txt MLE -
04_evil_2.txt MLE -
04_evil_3.txt MLE -
04_evil_4.txt MLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
#input = sys.stdin.readline
input = sys.stdin.buffer.readline #文字列はダメ
#sys.setrecursionlimit(1000000)
#import bisect
#import itertools
#import random
#from heapq import heapify, heappop, heappush
#from collections import defaultdict 
#from collections import deque
#import copy
#import math
#from functools import lru_cache
#@lru_cache(maxsize=None)
#MOD = pow(10,9) + 7
#MOD = 998244353
#dx = [1,0,-1,0]
#dy = [0,1,0,-1]

def solve(A,K):
    N = len(A)
    dp = [[0]*(K+1) for _ in range(N+1)]
    dp[0][0] = 1 
    #配るDP
    for i in range(N):
        a = A[i]
        for j in range(K+1):
            #使わない場合
            dp[i+1][j] = max(dp[i+1][j], dp[i][j])
            #使う場合
            if j+a <= K:
                dp[i+1][j+a] = max(dp[i+1][j+a], dp[i][j])
    used = set([])
    if dp[N][K] == 0:
        return used
    v = K
    for i in reversed(range(N)):
        a = A[i]
        if dp[i][v-a] == 1:
            used.add(i)
            v -= a

    return used

def main():
    N,K = map(int,input().split())
    A = list(map(int,input().split()))
    A.sort()

    X = solve(A,K)
    #print(X)
    A.reverse()
    Y = solve(A,K)
    #print(Y)
    ans = 0
    for x in X:
        if x in Y:
            ans += 1
    if ans == 0:
        print(-1)
    else:
        print(ans)
    

if __name__ == '__main__':
    main()
0