結果

問題 No.1201 お菓子配り-4
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-02-15 21:21:39
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,013 bytes
コンパイル時間 298 ms
コンパイル使用メモリ 87,224 KB
実行使用メモリ 78,176 KB
最終ジャッジ日時 2023-09-25 05:28:53
合計ジャッジ時間 52,623 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
77,728 KB
testcase_01 AC 2,069 ms
77,660 KB
testcase_02 AC 2,914 ms
77,612 KB
testcase_03 AC 1,457 ms
78,028 KB
testcase_04 AC 758 ms
77,480 KB
testcase_05 AC 1,774 ms
77,656 KB
testcase_06 AC 346 ms
77,132 KB
testcase_07 AC 848 ms
77,728 KB
testcase_08 AC 2,188 ms
77,544 KB
testcase_09 AC 1,677 ms
77,808 KB
testcase_10 AC 110 ms
77,520 KB
testcase_11 AC 498 ms
77,728 KB
testcase_12 AC 3,309 ms
77,912 KB
testcase_13 AC 186 ms
77,656 KB
testcase_14 AC 139 ms
77,244 KB
testcase_15 AC 2,622 ms
78,176 KB
testcase_16 AC 860 ms
77,792 KB
testcase_17 AC 1,084 ms
77,504 KB
testcase_18 AC 257 ms
77,392 KB
testcase_19 AC 247 ms
77,432 KB
testcase_20 AC 70 ms
71,424 KB
testcase_21 AC 70 ms
71,652 KB
testcase_22 AC 67 ms
71,500 KB
testcase_23 AC 71 ms
71,232 KB
testcase_24 AC 69 ms
71,116 KB
testcase_25 AC 69 ms
71,372 KB
testcase_26 AC 69 ms
71,516 KB
testcase_27 AC 71 ms
71,268 KB
testcase_28 AC 70 ms
71,620 KB
testcase_29 AC 69 ms
71,116 KB
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import ceil


def floor_sum_of_linear(L: int, R: int, a: int, b: int, mod: int) -> int:
    """
    ```
    sum((x * a + b) // mod for x in range(L, R))
    ```
    """
    if L >= R:
        return 0
    res = 0
    b += L * a
    n = R - L

    if b < 0:
        k = ceil(-b / mod)
        b += k * mod
        res -= n * k

    while n:
        q, a = a // mod, a % mod
        res += n * (n - 1) // 2 * q
        if b >= mod:
            q, b = b // mod, b % mod
            res += n * q
        n, b = (a * n + b) // mod, (a * n + b) % mod
        a, mod = mod, a

    return res


if __name__ == "__main__":
    import sys

    sys.setrecursionlimit(int(1e9))
    input = lambda: sys.stdin.readline().rstrip("\r\n")

    N = int(input())
    M = int(input())
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    ans = 0
    for a in A:
        for b in B:
            ans += floor_sum_of_linear(1, b + 1, a, 0, b)
    ans *= 2
    ans %= int(1e9 + 7)
    print(ans)
0