結果

問題 No.2452 Incline
ユーザー FromBooskaFromBooska
提出日時 2023-09-02 11:16:26
言語 PyPy3
(7.3.15)
結果
TLE  
実行時間 -
コード長 883 bytes
コンパイル時間 1,304 ms
コンパイル使用メモリ 86,584 KB
実行使用メモリ 71,320 KB
最終ジャッジ日時 2023-09-02 11:17:10
合計ジャッジ時間 5,986 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 72 ms
71,000 KB
testcase_01 AC 71 ms
71,320 KB
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

# 公差区間はN-1あるので、初項と右端項の差が(N-1)の倍数である必要がある
# 右端項が(N-1)個あるたびに、パターン数は(M+1)個となる
# するとR+1-Lに(N-1)個がn回入っていれば、n*(M+1)と残りの数
# この残りの数のカウントに時間がかかりそう、Nが巨大のときにTLEするだろう
# でもとりあえずやってみる

mod = 998244353
T = int(input())
for t in range(T):
    N, M, L, R = map(int, input().split())
    RL_interval = R+1-L
    N_count = RL_interval//(N-1)
    residual = RL_interval%(N-1)
    ans = N_count*(M+1)
    ans %= mod
    #print('RL_interval', RL_interval, 'N_count', N_count, 'residual', residual, 'ans', ans)
    for r in range(L, L+residual):
        calc = (M-r%(N-1)+1+N-2)//(N-1)
        ans += calc
        ans %= mod
        #print('r', r, 'calc', calc)
    print(ans)
0