結果

問題 No.1201 お菓子配り-4
ユーザー mkawa2
提出日時 2021-07-06 01:14:07
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
TLE  
実行時間 -
コード長 1,243 bytes
コンパイル時間 111 ms
コンパイル使用メモリ 12,544 KB
実行使用メモリ 21,376 KB
最終ジャッジ日時 2024-07-01 12:05:04
合計ジャッジ時間 9,784 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1 TLE * 1 -- * 34
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
int1 = lambda x: int(x)-1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()
dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
inf = 10**16
# md = 998244353
md = 10**9+7

# sum((a*i+b)//m for i in range(n))が求まる
# a,b>=0 m>=1

def floor_sum(n: int, m: int, a: int, b: int) -> int:
    ans = 0
    while 1:
        if a >= m:
            ans += (n-1)*n*(a//m)//2
            a %= m
        if b >= m:
            ans += n*(b//m)
            b %= m
        y_max = (a*n+b)//m
        x_max = y_max*m-b
        if y_max == 0: return ans
        ans += (n-(x_max+a-1)//a)*y_max%md
        ans %= md
        n, m, a, b = y_max, a, m, (a-x_max%a)%a

n = II()
m = II()
aa = LI()
bb = LI()

ans = 0
for a in aa:
    for b in bb:
        ans += 2*floor_sum(b+1, b, a, 0)
        ans %= md
print(ans)
0