結果
問題 | No.1861 Required Number |
ユーザー |
![]() |
提出日時 | 2022-03-04 21:48:33 |
言語 | PyPy3 (7.3.15) |
結果 |
MLE
(最新)
AC
(最初)
|
実行時間 | - |
コード長 | 836 bytes |
コンパイル時間 | 1,054 ms |
コンパイル使用メモリ | 82,132 KB |
実行使用メモリ | 814,988 KB |
最終ジャッジ日時 | 2024-07-18 22:46:40 |
合計ジャッジ時間 | 27,349 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 2 MLE * 1 |
other | AC * 42 TLE * 3 MLE * 1 |
ソースコード
import sysinput = sys.stdin.readlinefrom collections import *N, K = map(int, input().split())A = list(map(int, input().split()))dp1 = [[False]*(K+1) for _ in range(N+1)]dp1[0][0] = Truefor i in range(N):for j in range(K+1):if dp1[i][j]:dp1[i+1][j] = Trueif j+A[i]<=K:dp1[i+1][j+A[i]] = Trueif not dp1[N][K]:exit(print(-1))dp2 = [[False]*(K+1) for _ in range(N+1)]dp2[0][0] = Truefor i in range(N):for j in range(K+1):if dp2[i][j]:dp2[i+1][j] = Trueif j+A[N-1-i]<=K:dp2[i+1][j+A[N-1-i]] = Trueans = 0for i in range(N):ok = Truefor j in range(K+1):if dp1[i][j] and dp2[N-1-i][K-j]:ok = Falseif ok:ans += 1print(ans)