結果
| 問題 | No.3048 Swing | 
| コンテスト | |
| ユーザー |  | 
| 提出日時 | 2025-03-07 21:48:57 | 
| 言語 | Python3 (3.13.1 + numpy 2.2.1 + scipy 1.14.1) | 
| 結果 | 
                                TLE
                                 
                             | 
| 実行時間 | - | 
| コード長 | 1,078 bytes | 
| コンパイル時間 | 1,410 ms | 
| コンパイル使用メモリ | 12,032 KB | 
| 実行使用メモリ | 17,352 KB | 
| 最終ジャッジ日時 | 2025-03-07 21:49:15 | 
| 合計ジャッジ時間 | 18,331 ms | 
| ジャッジサーバーID (参考情報) | judge1 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| other | AC * 25 TLE * 1 -- * 32 | 
ソースコード
import math
def find_xn(x, n):
    if n == 0:
        return x
    
    if x > 0:
        k = math.ceil((math.sqrt(8 * x + 1) - 1) / 2)
        m = k + 1
        # 计算Xm
        sum_k = k * (k + 1) // 2
        Xm = x - sum_k + (k + 1)
    else:
        target = -x
        if target == 0:
            k = 0
        else:
            k = math.ceil((math.sqrt(8 * target + 1) - 1) / 2)
            while k * (k + 1) // 2 <= target:
                k += 1
        m = k
        sum_k = k * (k + 1) // 2
        Xm = x + sum_k
    
    if n < m:
        current = x
        for i in range(1, n + 1):
            if current > 0:
                current -= i
            else:
                current += i
        return current
    else:
        t_steps = n - m
        groups = t_steps // 2
        remainder = t_steps % 2
        Xn = Xm + groups 
        
        if remainder:
            i = m + 2 * groups + 1
            if Xn > 0:
                Xn -= i
            else:
                Xn += i
        return Xn
x, n = map(int, input().split())
print(find_xn(x, n)) 
            
            
            
        