結果

問題 No.1977 Extracting at Constant Intervals
ユーザー tassei903tassei903
提出日時 2022-05-17 02:52:47
言語 PyPy3
(7.3.13)
結果
AC  
実行時間 123 ms / 2,000 ms
コード長 1,446 bytes
コンパイル時間 323 ms
コンパイル使用メモリ 87,180 KB
実行使用メモリ 96,328 KB
最終ジャッジ日時 2023-07-30 14:31:10
合計ジャッジ時間 5,063 ms
ジャッジサーバーID
(参考情報)
judge5 / judge12
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,080 KB
testcase_01 AC 74 ms
71,152 KB
testcase_02 AC 87 ms
76,712 KB
testcase_03 AC 113 ms
91,020 KB
testcase_04 AC 88 ms
76,640 KB
testcase_05 AC 123 ms
93,420 KB
testcase_06 AC 97 ms
85,920 KB
testcase_07 AC 106 ms
89,528 KB
testcase_08 AC 103 ms
87,064 KB
testcase_09 AC 92 ms
78,616 KB
testcase_10 AC 113 ms
87,304 KB
testcase_11 AC 89 ms
76,628 KB
testcase_12 AC 87 ms
76,616 KB
testcase_13 AC 105 ms
89,452 KB
testcase_14 AC 111 ms
96,328 KB
testcase_15 AC 94 ms
83,236 KB
testcase_16 AC 107 ms
93,840 KB
testcase_17 AC 119 ms
91,152 KB
testcase_18 AC 103 ms
81,840 KB
testcase_19 AC 87 ms
77,604 KB
testcase_20 AC 119 ms
94,776 KB
testcase_21 AC 112 ms
87,796 KB
testcase_22 AC 108 ms
93,508 KB
testcase_23 AC 93 ms
76,968 KB
testcase_24 AC 112 ms
87,488 KB
testcase_25 AC 85 ms
76,388 KB
testcase_26 AC 87 ms
76,624 KB
testcase_27 AC 104 ms
82,604 KB
testcase_28 AC 87 ms
77,980 KB
testcase_29 AC 96 ms
84,160 KB
testcase_30 AC 117 ms
92,904 KB
testcase_31 AC 93 ms
82,220 KB
testcase_32 AC 96 ms
83,056 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