結果

問題 No.1515 Making Many Multiples
ユーザー shotoyooshotoyoo
提出日時 2022-07-01 00:55:20
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 707 ms / 2,000 ms
コード長 1,484 bytes
コンパイル時間 166 ms
コンパイル使用メモリ 82,832 KB
実行使用メモリ 109,108 KB
最終ジャッジ日時 2024-05-03 21:01:57
合計ジャッジ時間 10,516 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 38 ms
54,896 KB
testcase_01 AC 51 ms
66,776 KB
testcase_02 AC 707 ms
108,856 KB
testcase_03 AC 687 ms
108,904 KB
testcase_04 AC 677 ms
108,460 KB
testcase_05 AC 665 ms
109,108 KB
testcase_06 AC 228 ms
108,912 KB
testcase_07 AC 355 ms
108,860 KB
testcase_08 AC 230 ms
84,192 KB
testcase_09 AC 397 ms
92,728 KB
testcase_10 AC 406 ms
93,760 KB
testcase_11 AC 504 ms
99,240 KB
testcase_12 AC 362 ms
90,616 KB
testcase_13 AC 83 ms
77,792 KB
testcase_14 AC 544 ms
101,924 KB
testcase_15 AC 81 ms
77,756 KB
testcase_16 AC 626 ms
106,392 KB
testcase_17 AC 168 ms
93,172 KB
testcase_18 AC 149 ms
98,308 KB
testcase_19 AC 88 ms
86,136 KB
testcase_20 AC 173 ms
86,724 KB
testcase_21 AC 420 ms
107,684 KB
testcase_22 AC 73 ms
74,972 KB
testcase_23 AC 467 ms
108,432 KB
testcase_24 AC 41 ms
55,176 KB
testcase_25 AC 44 ms
61,488 KB
testcase_26 AC 41 ms
54,992 KB
testcase_27 AC 456 ms
108,276 KB
testcase_28 AC 293 ms
108,468 KB
testcase_29 AC 63 ms
72,300 KB
testcase_30 AC 81 ms
78,220 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys, random
input = lambda : sys.stdin.readline().rstrip()

write = lambda x: sys.stdout.write(x+"\n"); writef = lambda x: print("{:.12f}".format(x))
debug = lambda x: sys.stderr.write(x+"\n")
YES="Yes"; NO="No"; pans = lambda v: print(YES if v else NO); inf=10**18
LI = lambda : list(map(int, input().split()))
def debug(_l_):
    for s in _l_.split():
        print(f"{s}={eval(s)}", end=" ")
    print()
def dlist(*l, fill=0):
    if len(l)==1:
        return [fill]*l[0]
    ll = l[1:]
    return [dlist(*ll, fill=fill) for _ in range(l[0])]
sys.setrecursionlimit(3*10**5+10)

n,k,x,y = list(map(int, input().split()))
dp = [[-inf]*k for _ in range(k)]
x %= k
y %= k
dp[x][y] = dp[y][x] = 0
a = LI()
xs = [-inf]*k
ys = [-inf]*k
xs[x] = ys[y] = xs[y] = ys[x] = 0
for i in range(n):
    v0 = a[i]%k
    v = (-a[i]) % k
    for xx in range(k):
        yy = (v - xx) % k
        if dp[xx][yy]==-inf:
            continue
#         print(v, xx, yy)
        dp[xx][yy] += 1
        xs[xx] = max(xs[xx], dp[xx][yy])
        ys[yy] = max(ys[yy], dp[xx][yy])
    nxs = xs[:]
    nys = ys[:]
    for xx in range(k):
        dp[xx][v0] = max(dp[xx][v0], ys[xx])
        dp[v0][xx] = max(dp[v0][xx], xs[xx])
        nxs[xx] = max(nxs[xx], dp[xx][v0])
        nys[xx] = max(nys[xx], dp[v0][xx])
        nxs[v0] = max(nxs[v0], dp[v0][xx])
        nys[v0] = max(nys[v0], dp[xx][v0])
    xs = nxs
    ys = nys
#     break
ans = -inf
for item in dp:
    ans = max(ans, max(item))
print(ans)
0