結果
問題 |
No.2046 Ans Mod? Mod Ans!
|
ユーザー |
![]() |
提出日時 | 2025-03-31 17:21:17 |
言語 | PyPy3 (7.3.15) |
結果 |
AC
|
実行時間 | 1,509 ms / 4,000 ms |
コード長 | 1,226 bytes |
コンパイル時間 | 139 ms |
コンパイル使用メモリ | 82,248 KB |
実行使用メモリ | 119,812 KB |
最終ジャッジ日時 | 2025-03-31 17:22:34 |
合計ジャッジ時間 | 9,414 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
import bisect def main(): import sys input = sys.stdin.read data = input().split() N = int(data[0]) A = list(map(int, data[1:N+1])) A.sort() prefix = [0] * (N + 1) for i in range(N): prefix[i+1] = prefix[i] + A[i] max_A = A[-1] total = 0 for i in range(N): s = A[i] idx = bisect.bisect_right(A, s) count_l = N - idx sum_l = prefix[N] - prefix[idx] K = 0 k = 1 while True: low = k * s if low > max_A: break high = (k + 1) * s - 1 if k == 1: new_low = s + 1 else: new_low = low high_adj = min(high, max_A) if new_low > high_adj: k += 1 continue left = bisect.bisect_left(A, new_low) right = bisect.bisect_right(A, high_adj) count = right - left K += k * count if high_adj == max_A: break k += 1 contribution = s * (count_l + K) - sum_l total += contribution print(total) if __name__ == "__main__": main()