結果
問題 | No.3048 Swing |
ユーザー |
|
提出日時 | 2025-03-07 23:30:44 |
言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 1,368 bytes |
コンパイル時間 | 1,307 ms |
コンパイル使用メモリ | 161,768 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 02:25:58 |
合計ジャッジ時間 | 2,857 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 62 |
ソースコード
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define REP(i,n) for(int i=0;i<int(n);i++) int main(void){ cin.tie(nullptr); ios_base::sync_with_stdio(false); ll i,j; ll x,n; cin >> x >> n; if(x>0){ ll ng=-1,ok=2000000000; while(ok-ng>1){ ll m=(ok+ng)/2; if(x<=m*(m+1)/2) ok=m; else ng=m; } if(ok>=n){ cout << x-n*(n+1)/2 << endl; return 0; } ll p=(n-ok)/2; x-=ok*(ok+1)/2; if((n-ok)%2==0){ cout << x-p << endl; return 0; }else{ cout << x-p+n << endl; return 0; } }else{ x*=-1; ll ng=-1,ok=2000000000; while(ok-ng>1){ ll m=(ok+ng)/2; if(x<=m*(m+1)/2) ok=m; else ng=m; } x*=-1; if(ok>=n){ cout << x+n*(n+1)/2 << endl; return 0; } ll p=(n-ok)/2; x+=ok*(ok+1)/2; if(x==0){ if((n-ok)%2==0){ cout << x-p << endl; return 0; }else{ cout << x-p+n << endl; return 0; } }else{ if((n-ok)%2==0){ cout << x+p << endl; return 0; }else{ cout << x+p-n << endl; return 0; } } } return 0; }