結果

問題 No.1515 Making Many Multiples
ユーザー mkawa2mkawa2
提出日時 2023-11-17 15:50:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 680 ms / 2,000 ms
コード長 1,311 bytes
コンパイル時間 200 ms
コンパイル使用メモリ 81,700 KB
実行使用メモリ 114,420 KB
最終ジャッジ日時 2023-11-17 15:50:58
合計ジャッジ時間 11,062 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 37 ms
53,460 KB
testcase_01 AC 50 ms
64,608 KB
testcase_02 AC 650 ms
113,780 KB
testcase_03 AC 680 ms
114,420 KB
testcase_04 AC 656 ms
114,036 KB
testcase_05 AC 668 ms
114,164 KB
testcase_06 AC 152 ms
107,508 KB
testcase_07 AC 196 ms
107,764 KB
testcase_08 AC 448 ms
88,544 KB
testcase_09 AC 540 ms
97,916 KB
testcase_10 AC 562 ms
98,420 KB
testcase_11 AC 602 ms
104,596 KB
testcase_12 AC 484 ms
95,104 KB
testcase_13 AC 98 ms
76,052 KB
testcase_14 AC 594 ms
106,100 KB
testcase_15 AC 102 ms
76,052 KB
testcase_16 AC 666 ms
111,860 KB
testcase_17 AC 138 ms
91,900 KB
testcase_18 AC 106 ms
91,328 KB
testcase_19 AC 57 ms
72,644 KB
testcase_20 AC 185 ms
85,316 KB
testcase_21 AC 333 ms
107,380 KB
testcase_22 AC 70 ms
75,664 KB
testcase_23 AC 350 ms
107,892 KB
testcase_24 AC 36 ms
53,460 KB
testcase_25 AC 36 ms
53,460 KB
testcase_26 AC 36 ms
53,460 KB
testcase_27 AC 313 ms
106,740 KB
testcase_28 AC 206 ms
106,920 KB
testcase_29 AC 61 ms
72,576 KB
testcase_30 AC 76 ms
76,920 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(1000005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

# dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

n,k,x,y=LI()
aa=LI()

x%=k
y%=k
dp=[[-1]*k for _ in range(k)]
dp[x][y]=0
mx=[-1]*k
mx[x]=mx[y]=0

def update(i,j,v):
    if v>dp[i][j]:
        dp[i][j]=dp[j][i]=v
    if v>mx[i]:mx[i]=v
    if v>mx[j]:mx[j]=v

for a in aa:
    a%=k
    ijv=[]
    for i in range(k):
        if mx[i]!=-1:
            ijv.append((i,a,mx[i]))
        j=(-a-i)%k
        pre=dp[i][j]
        if pre!=-1:
            ijv.append((i,j,pre+1))
            ijv.append((i,a,pre+1))
            ijv.append((a,j,pre+1))
    for i,j,v in ijv:update(i,j,v)

print(max(mx))
0