結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 241 ms
77,284 KB
testcase_01 AC 2,079 ms
77,624 KB
testcase_02 AC 2,917 ms
77,620 KB
testcase_03 AC 1,461 ms
77,832 KB
testcase_04 AC 766 ms
77,556 KB
testcase_05 AC 1,778 ms
77,460 KB
testcase_06 AC 350 ms
77,092 KB
testcase_07 AC 849 ms
77,596 KB
testcase_08 AC 2,196 ms
77,540 KB
testcase_09 AC 1,690 ms
77,644 KB
testcase_10 AC 113 ms
77,512 KB
testcase_11 AC 500 ms
77,676 KB
testcase_12 AC 3,315 ms
77,640 KB
testcase_13 AC 188 ms
77,792 KB
testcase_14 AC 139 ms
76,924 KB
testcase_15 AC 2,618 ms
77,420 KB
testcase_16 AC 866 ms
77,888 KB
testcase_17 AC 1,093 ms
77,660 KB
testcase_18 AC 260 ms
77,396 KB
testcase_19 AC 249 ms
77,524 KB
testcase_20 AC 72 ms
71,008 KB
testcase_21 AC 74 ms
71,264 KB
testcase_22 AC 73 ms
71,184 KB
testcase_23 AC 73 ms
71,304 KB
testcase_24 AC 73 ms
71,308 KB
testcase_25 AC 72 ms
71,272 KB
testcase_26 AC 72 ms
71,112 KB
testcase_27 AC 74 ms
71,252 KB
testcase_28 AC 72 ms
71,268 KB
testcase_29 AC 73 ms
71,304 KB
testcase_30 TLE -
testcase_31 TLE -
testcase_32 TLE -
testcase_33 TLE -
testcase_34 TLE -
testcase_35 TLE -
権限があれば一括ダウンロードができます

ソースコード

diff #

# https://maspypy.github.io/library/mod/floor_sum_of_linear.hpp
# !sum((x * a + b) // mod for x in range(L, R))


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