結果
| 問題 |
No.1515 Making Many Multiples
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-04-16 16:40:27 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,246 bytes |
| コンパイル時間 | 234 ms |
| コンパイル使用メモリ | 82,072 KB |
| 実行使用メモリ | 67,096 KB |
| 最終ジャッジ日時 | 2025-04-16 16:41:20 |
| 合計ジャッジ時間 | 4,230 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | -- * 3 |
| other | AC * 2 TLE * 1 -- * 25 |
ソースコード
import sys
from collections import defaultdict
def main():
N, K, X, Y = map(int, sys.stdin.readline().split())
x0 = X % K
y0 = Y % K
A = list(map(int, sys.stdin.readline().split()))
current = defaultdict(int)
current[(x0, y0)] = 0
for a in A:
a_mod = a % K
next_dp = defaultdict(int)
for (a_prev, b_prev), score in current.items():
sum_three = (a_prev + b_prev + a_mod) % K
new_score = score + (1 if sum_three == 0 else 0)
# Transition 1: discard a_prev → new state (b_prev, a_mod)
key = (b_prev, a_mod)
if next_dp[key] < new_score:
next_dp[key] = new_score
# Transition 2: discard b_prev → new state (a_prev, a_mod)
key = (a_prev, a_mod)
if next_dp[key] < new_score:
next_dp[key] = new_score
# Transition 3: discard a_mod → new state (a_prev, b_prev)
key = (a_prev, b_prev)
if next_dp[key] < new_score:
next_dp[key] = new_score
current = next_dp
print(max(current.values()) if current else 0)
if __name__ == "__main__":
main()
lam6er