結果

問題 No.3048 Swing
ユーザー flippergo
提出日時 2025-06-02 08:21:29
言語 PyPy3
(7.3.15)
結果
WA  
実行時間 -
コード長 781 bytes
コンパイル時間 669 ms
コンパイル使用メモリ 82,376 KB
実行使用メモリ 54,296 KB
最終ジャッジ日時 2025-06-02 08:21:34
合計ジャッジ時間 4,979 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 29 WA * 30
権限があれば一括ダウンロードができます

ソースコード

diff #

x,n = map(int,input().split())
if x<=0:
    high = x
    low = 0
    while high-low>1:
        mid = (high+low)//2
        if x+(mid*(mid+1))//2>0:
            high = mid
        else:
            low = mid
    k = high
    if n<k:
        ans = x+(n*(n+1))//2
    elif (n-k)%2==0:
        s = x+(k*(k+1))//2
        ans = s+(n-k)//2
    else:
        t = x+(k*(k+1))//2-(k+1)
        ans = t-(n-k)//2
else:
    high = x
    low = 0
    while high-low>1:
        mid = (high+low)//2
        if x-(mid*(mid+1))//2<=0:
            high = mid
        else:
            low = mid
    k = high
    if n<k:
        ans = x-(n*(n+1))//2
    elif (n-k)%2==0:
        s = x-(k*(k+1))//2
        ans = s-(n-k)//2
    else:
        t = x-(k*(k+1))//2+(k+1)
        ans = t+(n-k)//2
print(ans)
0