結果

問題 No.3048 Swing
コンテスト
ユーザー Kude
提出日時 2025-03-07 21:08:11
言語 PyPy3
(7.3.17)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 56 ms / 2,000 ms
+ 922µs
コード長 555 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 236 ms
コンパイル使用メモリ 96,360 KB
実行使用メモリ 79,184 KB
最終ジャッジ日時 2026-07-12 10:42:40
合計ジャッジ時間 6,018 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge2_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 62
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

x, n = map(int, input().split())
i = 0
if x > 0:
    # x-i(i+1)/2<=0
    l, r = 0, 10 ** 10
    while r - l > 1:
        c = (l + r) // 2
        if c * (c + 1) // 2 >= x:
            r = c
        else:
            l = c
    i = min(l, n)
    x -= i * (i + 1) // 2
else:
    # x+i(i+1)/2>0
    l, r = 0, 10 ** 10
    while r - l > 1:
        c = (l + r) // 2
        if x + c * (c + 1) // 2 > 0:
            r = c
        else:
            l = c
    i = min(r, n)
    x += i * (i + 1) // 2
t = (n - i) // 2
x += t
i += 2 * t
if i < n:
    x -= n
print(x)
0