結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 239 ms
154,156 KB
testcase_01 AC 2,055 ms
77,624 KB
testcase_02 AC 2,920 ms
78,288 KB
testcase_03 AC 1,448 ms
77,416 KB
testcase_04 AC 762 ms
77,544 KB
testcase_05 AC 1,741 ms
78,080 KB
testcase_06 AC 349 ms
76,992 KB
testcase_07 AC 853 ms
78,052 KB
testcase_08 AC 2,203 ms
78,156 KB
testcase_09 AC 1,662 ms
77,900 KB
testcase_10 AC 110 ms
77,764 KB
testcase_11 AC 494 ms
77,548 KB
testcase_12 AC 3,294 ms
78,088 KB
testcase_13 AC 180 ms
77,376 KB
testcase_14 AC 134 ms
76,892 KB
testcase_15 AC 2,688 ms
78,284 KB
testcase_16 AC 852 ms
77,492 KB
testcase_17 AC 1,093 ms
77,368 KB
testcase_18 AC 251 ms
77,356 KB
testcase_19 AC 242 ms
77,532 KB
testcase_20 AC 71 ms
71,116 KB
testcase_21 AC 71 ms
71,316 KB
testcase_22 AC 71 ms
71,568 KB
testcase_23 AC 69 ms
71,264 KB
testcase_24 AC 71 ms
71,272 KB
testcase_25 AC 68 ms
71,084 KB
testcase_26 AC 72 ms
71,556 KB
testcase_27 AC 71 ms
71,620 KB
testcase_28 AC 71 ms
71,256 KB
testcase_29 AC 69 ms
71,728 KB
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

from math import ceil

MOD = int(1e9 + 7)


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
        res %= MOD
        if b >= mod:
            q, b = b // mod, b % mod
            res += n * q
            res %= MOD
        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()))
    res = 0
    for a in A:
        for b in B:
            res += floor_sum_of_linear(1, b + 1, a, 0, b)
    res *= 2
    res %= MOD
    print(res)
0