結果

問題 No.2452 Incline
ユーザー mkawa2mkawa2
提出日時 2023-09-01 22:10:10
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 242 ms / 2,000 ms
コード長 1,054 bytes
コンパイル時間 400 ms
コンパイル使用メモリ 87,268 KB
実行使用メモリ 79,700 KB
最終ジャッジ日時 2023-09-01 22:10:17
合計ジャッジ時間 3,218 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 69 ms
71,328 KB
testcase_01 AC 71 ms
71,324 KB
testcase_02 AC 71 ms
71,428 KB
testcase_03 AC 226 ms
78,416 KB
testcase_04 AC 242 ms
79,576 KB
testcase_05 AC 235 ms
79,700 KB
testcase_06 AC 167 ms
77,760 KB
testcase_07 AC 213 ms
79,512 KB
testcase_08 AC 159 ms
77,648 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(1000005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
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 = -1-(-1 << 63)
# md = 10**9+7
md = 998244353

def calc(n,l,r):
    ans=0
    dr=r//(n-1)+1
    dl=l//(n-1)+1
    ans+=max(dl-1,0)*(r-l+1)
    c=dr-dl
    ans+=(r+1)*c-(n-1)*(dl+dr-1)*c//2
    return ans

def solve():
    n,m,l,r=LI()
    ans=r-l+1
    ans+=calc(n,l,r)
    l,r=m-r,m-l
    ans+=calc(n,l,r)

    print(ans%md)

for _ in range(II()):solve()
0