結果

問題 No.3048 Swing
コンテスト
ユーザー Kude
提出日時 2025-03-07 21:08:11
言語 PyPy3
(8.0.0 + ACL)
コンパイル:
pypy3 -mpy_compile _filename_
実行:
pypy3 _filename_
結果
AC  
実行時間 34 ms / 2,000 ms
+ 356µs
コード長 555 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 84 ms
コンパイル使用メモリ 64,856 KB
実行使用メモリ 53,916 KB
最終ジャッジ日時 2026-10-21 06:33:16
合計ジャッジ時間 5,110 ms
ジャッジサーバーID
(参考情報)
judge5_0 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 63
権限があれば一括ダウンロードができます

ソースコード

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