結果
| 問題 |
No.3048 Swing
|
| コンテスト | |
| ユーザー |
SourCreamOnion
|
| 提出日時 | 2025-03-07 22:14:01 |
| 言語 | PyPy3 (7.3.15) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,448 bytes |
| コンパイル時間 | 462 ms |
| コンパイル使用メモリ | 82,904 KB |
| 実行使用メモリ | 56,780 KB |
| 最終ジャッジ日時 | 2025-03-07 22:14:08 |
| 合計ジャッジ時間 | 4,734 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 47 WA * 11 |
ソースコード
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()
minus=False
if X<0:
minus=True
X=abs(X)
#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==0:
if minus:
print(-1*(now))
else:
print(now)
elif cnt%2==0:
if minus:
print(-1*(now+cnt//2))
else:
print(now+cnt//2)
else:
if minus:
print(-1*(now-(ok+1)-(cnt-1)//2))
else:
print(now-(ok+1)-(cnt-1)//2)
SourCreamOnion