結果
| 問題 |
No.1977 Extracting at Constant Intervals
|
| コンテスト | |
| ユーザー |
lam6er
|
| 提出日時 | 2025-03-26 15:53:18 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
TLE
|
| 実行時間 | - |
| コード長 | 1,241 bytes |
| コンパイル時間 | 187 ms |
| コンパイル使用メモリ | 82,180 KB |
| 実行使用メモリ | 91,276 KB |
| 最終ジャッジ日時 | 2025-03-26 15:53:43 |
| 合計ジャッジ時間 | 5,313 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 1 TLE * 1 -- * 29 |
ソースコード
import sys
import math
def main():
N, M, L = map(int, sys.stdin.readline().split())
A = list(map(int, sys.stdin.readline().split()))
count = [0] * L
for r in range(L):
# Solve for t'*N ≡ r mod L
g = math.gcd(N, L)
if r % g != 0:
count[r] = 0
continue
new_N = N // g
new_L = L // g
new_r = r // g
# Find modular inverse of new_N modulo new_L
try:
inv_N = pow(new_N, -1, new_L)
except ValueError:
# Shouldn't happen as new_N and new_L are coprime
count[r] = 0
continue
t0 = (new_r * inv_N) % new_L
if t0 >= M:
count[r] = 0
else:
# Number of solutions: floor((M-1 - t0) / new_L) + 1
m_max = (M - 1 - t0) // new_L
count[r] = m_max + 1
max_C = -float('inf')
for i in range(1, L+1):
current_sum = 0
for k in range(N):
# j is k+1 in 1-based
r = (i - (k+1)) % L
current_sum += A[k] * count[r]
if current_sum > max_C:
max_C = current_sum
print(max_C)
if __name__ == "__main__":
main()
lam6er