結果
| 問題 |
No.3048 Swing
|
| コンテスト | |
| ユーザー |
SourCreamOnion
|
| 提出日時 | 2025-03-07 22:03:59 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,501 bytes |
| コンパイル時間 | 751 ms |
| コンパイル使用メモリ | 82,088 KB |
| 実行使用メモリ | 56,868 KB |
| 最終ジャッジ日時 | 2025-03-07 22:04:05 |
| 合計ジャッジ時間 | 5,684 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 30 WA * 28 |
ソースコード
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate, combinations, permutations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from operator import itemgetter
import math
from heapq import heapify, heappush, heappop
LMI=lambda:list(map(int, input().split()))
LMS=lambda:list(map(str, input().split()))
MI=lambda:map(int, input().split())
MS=lambda:map(str, input().split())
II=lambda:int(input())
IS=lambda:input().split()
LI=lambda:list(input())
X,N=MI()
X=abs(X)
# def calc(x, n):
# tmp=n*(n + 1)//2
# if x<=0:
# if x+tmp<=0:
# return x + tmp
# else:
# y=(x + tmp)//2
# return (x + tmp)-2*y
# else:
# if x - tmp > 0:
# return x - tmp
# else:
# y=(-x + tmp)//2
# return (x - tmp) + 2*y
#OK、NGを判断するための関数
def cond(X, N):
return X >= N*(N+1)//2
ok, ng = 0, 10**18+1
#okとngの値が連番になるまで繰り返す
while abs(ok - ng)>1:
#真ん中の値を計算
mi = (ok + ng) // 2
#条件判断の関数を使う
if cond(X, mi):
#okなら真ん中の値をokにし狭める
ok = mi
else:
#ngなら真ん中の値をngにし狭める
ng = mi
if ok>=N:
print(X - N*(N + 1)//2)
exit()
else:
cnt=N-ok
now=X-ok*(ok + 1)//2
if cnt%2==0:
print(now+cnt//2)
else:
print(now-(ok+1)-(cnt-1)//2)
SourCreamOnion