結果

問題 No.3048 Swing
ユーザー moon17
提出日時 2025-03-07 21:27:13
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 37 ms / 2,000 ms
コード長 530 bytes
コンパイル時間 172 ms
コンパイル使用メモリ 82,160 KB
実行使用メモリ 54,208 KB
最終ジャッジ日時 2025-06-20 02:24:09
合計ジャッジ時間 3,790 ms
ジャッジサーバーID
(参考情報)
judge1 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 62
権限があれば一括ダウンロードができます

ソースコード

diff #

x,n=map(int,input().split())
def judge(m):
  return m*(m+1)//2<=abs(x)
ok,ng=0,1<<60
while abs(ok-ng)>1:
  mid=ok+ng>>1
  if judge(mid):
    ok=mid
  else:
    ng=mid
ans=-100
if n<=ok:
  if x<=0:
    ans=x+n*(n+1)//2
  else:
    ans=x-n*(n+1)//2
else:
  if x<=0:
    x0=x+ok*(ok+1)//2
  else:
    x0=x-ok*(ok+1)//2
  if x0<=0:
    x1=x0+ok+1
  else:
    x1=x0-ok-1
  n-=ok
  if n%2:
    if x1<=0:
      ans=x1-(n-1)//2
    else:
      ans=x1+(n-1)//2
  else:
    if x0<=0:
      ans=x0-n//2
    else:
      ans=x0+n//2
print(ans)
0