結果

問題 No.2001 Distanced Triple
ユーザー Ricky_pon
提出日時 2022-07-09 11:28:03
言語 Python3
(3.13.1 + numpy 2.2.1 + scipy 1.14.1)
結果
AC  
実行時間 34 ms / 2,000 ms
コード長 479 bytes
コンパイル時間 634 ms
コンパイル使用メモリ 12,416 KB
実行使用メモリ 10,752 KB
最終ジャッジ日時 2024-12-30 11:46:27
合計ジャッジ時間 2,728 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

def f(P, Q, R):
    return (R*(R+1)*(2*R+1)//6 + (P+Q)*R*(R+1)//2+ P*Q*R) // 2

L, R = map(int, input().split())
A, B, C = map(int, input().split())

if C >= B+A:
    if L+C > R:
        print(0)
        quit()
    P, Q = C-L-2*A-2*B+2, -C-L+1
    ans = f(P, Q, R) - f(P, Q, L+C-1)
    ans %= 998244353
    print(ans)
else:
    if L+A+B > R:
        print(0)
        quit()
    P, Q = -B-L-A+1, -B-L-A+2
    ans = f(P, Q, R) - f(P, Q, L+A+B-1)
    ans %= 998244353
    print(ans)
0