結果

問題 No.1201 お菓子配り-4
ユーザー 草苺奶昔草苺奶昔
提出日時 2023-03-11 15:14:27
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 1,002 bytes
コンパイル時間 1,015 ms
コンパイル使用メモリ 81,736 KB
実行使用メモリ 76,056 KB
最終ジャッジ日時 2023-10-18 09:56:21
合計ジャッジ時間 51,540 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 201 ms
75,312 KB
testcase_01 AC 2,026 ms
75,652 KB
testcase_02 AC 2,910 ms
75,816 KB
testcase_03 AC 1,435 ms
75,640 KB
testcase_04 AC 731 ms
75,632 KB
testcase_05 AC 1,715 ms
75,736 KB
testcase_06 AC 303 ms
75,312 KB
testcase_07 AC 813 ms
75,780 KB
testcase_08 AC 2,147 ms
75,804 KB
testcase_09 AC 1,630 ms
75,740 KB
testcase_10 AC 77 ms
75,768 KB
testcase_11 AC 461 ms
75,624 KB
testcase_12 AC 3,258 ms
75,852 KB
testcase_13 AC 150 ms
75,608 KB
testcase_14 AC 102 ms
75,308 KB
testcase_15 AC 2,568 ms
75,784 KB
testcase_16 AC 824 ms
75,624 KB
testcase_17 AC 1,057 ms
75,636 KB
testcase_18 AC 221 ms
75,620 KB
testcase_19 AC 212 ms
75,604 KB
testcase_20 AC 38 ms
53,532 KB
testcase_21 AC 39 ms
53,532 KB
testcase_22 AC 38 ms
53,532 KB
testcase_23 AC 38 ms
53,532 KB
testcase_24 AC 38 ms
53,532 KB
testcase_25 AC 38 ms
53,532 KB
testcase_26 AC 38 ms
53,532 KB
testcase_27 AC 38 ms
53,532 KB
testcase_28 AC 38 ms
53,532 KB
testcase_29 AC 37 ms
53,532 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, div: int) -> int:
    """
    ```
    sum((x * a + b) // div 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 / div)
        b += k * div
        res -= n * k

    while n:
        q, a = a // div, a % div
        res += n * (n - 1) // 2 * q
        # res %= MOD
        if b >= div:
            q, b = b // div, b % div
            res += n * q
            # res %= MOD
        n, b = (a * n + b) // div, (a * n + b) % div
        a, div = div, a

    return res


if __name__ == "__main__":
    n = int(input())
    m = int(input())
    nums1 = list(map(int, input().split()))
    nums2 = list(map(int, input().split()))

    res = 0
    for a in nums1:
        for b in nums2:
            res += floor_sum_of_linear(1, b + 1, a, 0, b)
            res %= MOD
    res *= 2
    res %= MOD
    print(res)
0