結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 305 ms
77,364 KB
testcase_01 AC 2,846 ms
77,800 KB
testcase_02 TLE -
testcase_03 AC 1,995 ms
77,632 KB
testcase_04 AC 1,028 ms
77,840 KB
testcase_05 AC 2,440 ms
77,820 KB
testcase_06 AC 459 ms
77,052 KB
testcase_07 AC 1,151 ms
77,836 KB
testcase_08 AC 3,018 ms
78,656 KB
testcase_09 AC 2,283 ms
78,380 KB
testcase_10 AC 121 ms
77,928 KB
testcase_11 AC 662 ms
77,640 KB
testcase_12 TLE -
testcase_13 AC 229 ms
77,572 KB
testcase_14 AC 164 ms
77,304 KB
testcase_15 AC 3,657 ms
78,052 KB
testcase_16 AC 1,181 ms
77,648 KB
testcase_17 AC 1,486 ms
77,716 KB
testcase_18 AC 329 ms
77,508 KB
testcase_19 AC 312 ms
77,520 KB
testcase_20 AC 72 ms
71,304 KB
testcase_21 AC 73 ms
71,336 KB
testcase_22 AC 73 ms
71,252 KB
testcase_23 AC 71 ms
71,776 KB
testcase_24 AC 71 ms
71,188 KB
testcase_25 AC 73 ms
71,412 KB
testcase_26 AC 73 ms
71,520 KB
testcase_27 AC 72 ms
71,332 KB
testcase_28 AC 73 ms
71,468 KB
testcase_29 AC 72 ms
71,264 KB
testcase_30 TLE -
testcase_31 -- -
testcase_32 -- -
testcase_33 -- -
testcase_34 -- -
testcase_35 -- -
権限があれば一括ダウンロードができます

ソースコード

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 = res + n * (n - 1) // 2 * q
        res %= 1 << 128
        if b >= mod:
            q, b = b // mod, b % mod
            res = res + n * q
            res %= 1 << 128
        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