結果
問題 | No.1457 ツブ消ししとるなHard |
ユーザー |
![]() |
提出日時 | 2025-03-20 21:05:36 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 64 ms / 2,000 ms |
コード長 | 1,679 bytes |
コンパイル時間 | 188 ms |
コンパイル使用メモリ | 82,604 KB |
実行使用メモリ | 66,080 KB |
最終ジャッジ日時 | 2025-03-20 21:05:42 |
合計ジャッジ時間 | 2,006 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 17 |
ソースコード
import sysdef main():N, M, X, Y, Z = map(int, sys.stdin.readline().split())A = list(map(int, sys.stdin.readline().split()))must_keep = []must_remove = []optional = []for a in A:if a >= X:must_keep.append(a)elif a <= Y:must_remove.append(a)else:optional.append(a)m_keep = len(must_keep)sum_m_keep = sum(must_keep)k_opt = len(optional)if m_keep > M:print("Handicapped")returnif k_opt == 0:possible = 0if m_keep >=1 and m_keep <= M:if sum_m_keep == Z * m_keep:possible = 1print(possible)returnmax_sum = sum(optional)max_t = k_optdp = [[0] * (max_sum + 1) for _ in range(max_t + 1)]dp[0][0] = 1for a in optional:for t in range(max_t, 0, -1):for s in range(max_sum, -1, -1):if dp[t-1][s]:new_s = s + aif new_s <= max_sum:dp[t][new_s] += dp[t-1][s]answer = 0t_max = min(k_opt, M - m_keep)for t in range(0, t_max + 1):total_t = m_keep + tif total_t < 1 or total_t > M:continuerequired_s = Z * total_t - sum_m_keepif required_s < 0:continueif t == 0:if required_s == 0 and sum_m_keep == Z * m_keep:answer += 1else:if required_s <= max_sum:answer += dp[t][required_s]print(answer if answer > 0 else 0)if __name__ == "__main__":main()