結果
問題 | No.1977 Extracting at Constant Intervals |
ユーザー |
![]() |
提出日時 | 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 sysimport mathdef main():N, M, L = map(int, sys.stdin.readline().split())A = list(map(int, sys.stdin.readline().split()))count = [0] * Lfor r in range(L):# Solve for t'*N ≡ r mod Lg = math.gcd(N, L)if r % g != 0:count[r] = 0continuenew_N = N // gnew_L = L // gnew_r = r // g# Find modular inverse of new_N modulo new_Ltry:inv_N = pow(new_N, -1, new_L)except ValueError:# Shouldn't happen as new_N and new_L are coprimecount[r] = 0continuet0 = (new_r * inv_N) % new_Lif t0 >= M:count[r] = 0else:# Number of solutions: floor((M-1 - t0) / new_L) + 1m_max = (M - 1 - t0) // new_Lcount[r] = m_max + 1max_C = -float('inf')for i in range(1, L+1):current_sum = 0for k in range(N):# j is k+1 in 1-basedr = (i - (k+1)) % Lcurrent_sum += A[k] * count[r]if current_sum > max_C:max_C = current_sumprint(max_C)if __name__ == "__main__":main()