結果
問題 |
No.3048 Swing
|
ユーザー |
![]() |
提出日時 | 2025-03-07 21:08:37 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 2 ms / 2,000 ms |
コード長 | 789 bytes |
コンパイル時間 | 3,714 ms |
コンパイル使用メモリ | 251,216 KB |
実行使用メモリ | 7,844 KB |
最終ジャッジ日時 | 2025-06-20 02:23:15 |
合計ジャッジ時間 | 4,824 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
other | AC * 62 |
ソースコード
#include <stdio.h> #include <bits/stdc++.h> #include <atcoder/all> using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000000 #define Inf64 1000000000000000001LL int main(){ long long x,n; cin>>x>>n; long long nn = n; long long ok = 0; long long ng = 2000000005; long long over; if(x > 0)over = x; else over = -x+1; while(ng-ok>1LL){ long long mid= (ok+ng)/2; if(mid * (mid+1) / 2 <over)ok = mid; else ng = mid; } if(ok >= n){ if(x <= 0)x += n*(n+1)/2; else x -= n*(n+1)/2; } else{ if(x<=0)x += ok*(ok+1)/2; else x -= ok*(ok+1)/2; n -= ok; if(x<=0)x -= n/2; else x += n/2; n %= 2; if(n){ if(x<=0)x += nn; else x-=nn; } } cout<<x<<endl; return 0; }