結果
問題 | No.1515 Making Many Multiples |
ユーザー |
![]() |
提出日時 | 2021-05-24 21:37:45 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 381 ms / 2,000 ms |
コード長 | 710 bytes |
コンパイル時間 | 164 ms |
コンパイル使用メモリ | 82,280 KB |
実行使用メモリ | 108,032 KB |
最終ジャッジ日時 | 2024-10-13 05:53:53 |
合計ジャッジ時間 | 6,647 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 28 |
ソースコード
N, K, x, y = map(int, input().split()) A = list(map(lambda x: int(x) % K, input().split())) x %= K y %= K # dp[i,j]: 手持ちがi,j -> 最大スコア inf = 10**5 inf = 10 dp = [[-inf] * K for _ in range(K)] memo = [-inf] * K dp[x][y] = 0 dp[y][x] = 0 memo[x] = 0 memo[y] = 0 for a in A: for x in range(K): y = (K - x - a) % K if dp[x][y] >= 0: dp[x][y] += 1 memo[x] = max(memo[x], dp[x][y]) for x in range(K): if memo[x] < 0: continue dp[x][a] = max(dp[x][a], memo[x]) dp[a][x] = max(dp[x][a], memo[x]) memo[a] = max(dp[a]) ans = 0 for i in range(K): for j in range(K): ans = max(ans, dp[i][j]) print(ans)