結果

問題 No.1977 Extracting at Constant Intervals
ユーザー tassei903tassei903
提出日時 2022-05-17 02:52:47
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 74 ms / 2,000 ms
コード長 1,446 bytes
コンパイル時間 142 ms
コンパイル使用メモリ 82,576 KB
実行使用メモリ 92,592 KB
最終ジャッジ日時 2024-04-17 15:39:30
合計ジャッジ時間 2,875 ms
ジャッジサーバーID
(参考情報)
judge4 / judge3
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 31 ms
52,608 KB
testcase_01 AC 31 ms
52,224 KB
testcase_02 AC 43 ms
66,432 KB
testcase_03 AC 68 ms
90,112 KB
testcase_04 AC 42 ms
65,920 KB
testcase_05 AC 74 ms
92,592 KB
testcase_06 AC 50 ms
76,160 KB
testcase_07 AC 59 ms
83,712 KB
testcase_08 AC 60 ms
80,128 KB
testcase_09 AC 48 ms
70,016 KB
testcase_10 AC 67 ms
86,756 KB
testcase_11 AC 46 ms
65,920 KB
testcase_12 AC 44 ms
66,816 KB
testcase_13 AC 59 ms
82,304 KB
testcase_14 AC 66 ms
90,112 KB
testcase_15 AC 50 ms
74,368 KB
testcase_16 AC 61 ms
87,040 KB
testcase_17 AC 73 ms
90,276 KB
testcase_18 AC 57 ms
77,184 KB
testcase_19 AC 44 ms
68,096 KB
testcase_20 AC 70 ms
91,776 KB
testcase_21 AC 72 ms
86,528 KB
testcase_22 AC 63 ms
87,680 KB
testcase_23 AC 48 ms
69,376 KB
testcase_24 AC 68 ms
86,528 KB
testcase_25 AC 41 ms
64,640 KB
testcase_26 AC 43 ms
65,664 KB
testcase_27 AC 58 ms
78,080 KB
testcase_28 AC 46 ms
67,968 KB
testcase_29 AC 51 ms
75,392 KB
testcase_30 AC 67 ms
89,856 KB
testcase_31 AC 50 ms
73,100 KB
testcase_32 AC 52 ms
75,776 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys
input = lambda :sys.stdin.readline()[:-1]
ni = lambda :int(input())
na = lambda :list(map(int,input().split()))
yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES")
no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO")
#######################################################################
def xgcd(a, b):
    x0, y0, x1, y1 = 1, 0, 0, 1
    while b != 0:
        q, a, b = a // b, b, a % b
        x0, x1 = x1, x0 - q * x1
        y0, y1 = y1, y0 - q * y1
    return a, x0, y0

def modinv(a, m):
    g, x, y = xgcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
N,M,L = na()
a = na()
from math import gcd
ans = -float("inf")
g = gcd(N, L)
n = N//g
R = L//g
u = modinv(R, n)
for x in range(g):
    z = [0]
    for i in range(n):
        z.append(z[-1] + a[(x + i * L)%N])
    f = R-(-n*M)%R
    l = 0
    r = (n * M - 1) // R + 1
    for i in range(n):
        if i < f:
            ans = max(ans, z[r%n] - z[l%n] + z[-1] * (r//n-l//n))
            #print("< ",l, r,z[r%n] - z[l%n] + z[-1] * (r//n-l//n))
        l += u
        r += u
    l = 0
    r = (n * M - 1) // R 
    for i in range(n):
        i = (R-i-1)//n * n + i
        if i >= f:
            ans = max(ans, z[r%n] - z[l%n] + z[-1] * (r//n-l//n))
            #print(">=",l, r,z[r%n] - z[l%n] + z[-1] * (r//n-l//n))
        l += u
        r += u

print(ans)
0