結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 240 ms
77,508 KB
testcase_01 AC 2,060 ms
77,844 KB
testcase_02 AC 2,910 ms
77,792 KB
testcase_03 AC 1,456 ms
78,008 KB
testcase_04 AC 757 ms
77,688 KB
testcase_05 AC 1,776 ms
77,848 KB
testcase_06 AC 345 ms
76,948 KB
testcase_07 AC 848 ms
77,584 KB
testcase_08 AC 2,195 ms
77,784 KB
testcase_09 AC 1,676 ms
77,516 KB
testcase_10 AC 112 ms
77,680 KB
testcase_11 AC 506 ms
77,824 KB
testcase_12 AC 3,318 ms
78,044 KB
testcase_13 AC 183 ms
77,988 KB
testcase_14 AC 138 ms
77,272 KB
testcase_15 AC 2,624 ms
78,208 KB
testcase_16 AC 859 ms
77,944 KB
testcase_17 AC 1,084 ms
77,752 KB
testcase_18 AC 256 ms
77,388 KB
testcase_19 AC 246 ms
77,632 KB
testcase_20 AC 68 ms
71,296 KB
testcase_21 AC 70 ms
71,336 KB
testcase_22 AC 69 ms
71,076 KB
testcase_23 AC 69 ms
71,320 KB
testcase_24 AC 68 ms
71,536 KB
testcase_25 AC 71 ms
71,756 KB
testcase_26 AC 71 ms
71,444 KB
testcase_27 AC 70 ms
71,512 KB
testcase_28 AC 71 ms
71,360 KB
testcase_29 AC 70 ms
71,360 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 = res + n * (n - 1) // 2 * q
        if b >= mod:
            q, b = b // mod, b % mod
            res = 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