結果

問題 No.1201 お菓子配り-4
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-02-15 21:18:25
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 901 bytes
コンパイル時間 272 ms
コンパイル使用メモリ 87,304 KB
実行使用メモリ 154,648 KB
最終ジャッジ日時 2023-09-25 05:24:56
合計ジャッジ時間 53,053 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 243 ms
154,648 KB
testcase_01 AC 2,078 ms
77,692 KB
testcase_02 AC 2,923 ms
77,472 KB
testcase_03 AC 1,460 ms
77,844 KB
testcase_04 AC 760 ms
77,548 KB
testcase_05 AC 1,776 ms
77,688 KB
testcase_06 AC 346 ms
77,128 KB
testcase_07 AC 848 ms
77,436 KB
testcase_08 AC 2,197 ms
77,592 KB
testcase_09 AC 1,674 ms
77,616 KB
testcase_10 AC 109 ms
77,584 KB
testcase_11 AC 498 ms
77,924 KB
testcase_12 AC 3,312 ms
77,652 KB
testcase_13 AC 182 ms
77,772 KB
testcase_14 AC 138 ms
77,120 KB
testcase_15 AC 2,642 ms
77,584 KB
testcase_16 AC 865 ms
77,888 KB
testcase_17 AC 1,088 ms
77,604 KB
testcase_18 AC 258 ms
77,544 KB
testcase_19 AC 242 ms
77,404 KB
testcase_20 AC 68 ms
71,292 KB
testcase_21 AC 69 ms
71,436 KB
testcase_22 AC 68 ms
71,364 KB
testcase_23 AC 78 ms
71,460 KB
testcase_24 AC 68 ms
71,364 KB
testcase_25 AC 69 ms
71,392 KB
testcase_26 AC 69 ms
71,280 KB
testcase_27 AC 70 ms
71,276 KB
testcase_28 AC 68 ms
71,364 KB
testcase_29 AC 70 ms
71,284 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__":
    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 %= 10**9 + 7
    print(ans)
0