結果
| 問題 |
No.3048 Swing
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-07 21:23:21 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 1,571 bytes |
| コンパイル時間 | 6,218 ms |
| コンパイル使用メモリ | 334,016 KB |
| 実行使用メモリ | 8,612 KB |
| 最終ジャッジ日時 | 2025-03-07 21:23:33 |
| 合計ジャッジ時間 | 11,040 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 32 RE * 26 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <atcoder/all>
using namespace atcoder;
using mint = atcoder::static_modint<998244353>;
// using mint = atcoder::static_modint<1000000007>;
using ld = long double;
using ll = long long;
#define mp(a,b) make_pair(a,b)
#define rep(i,s,n) for(int i=s; i<(int)n; i++)
const vector<int> dx{1,0,-1,0},dy{0,1,0,-1};
ll solve_posi(__int128_t x,__int128_t n){
if(n*(n+1)/2<=x){
return x-(n+1)*n/2;
}
__int128_t L=0,R=x;
while(R-L>1){
__int128_t mid=(L+R)/2;
if(x-mid*(mid+1)/2<=0)R=mid;
else L=mid;
}
// cout << (ll)L << " " << (ll)R;
__int128_t x_R=x-R*(R+1)/2;
if((n-R)%2==0){
__int128_t ans=x_R-(n-R)/2;
return ans;
}
else{
__int128_t ans=x_R+R+1+(n-R)/2;
return ans;
}
}
ll solve_nega(__int128_t x,__int128_t n){
assert(false);
if(x+n*(n+1)/2<=0){
return x+(n+1)*n/2;
}
__int128_t L=0,R=x;
while(R-L>1){
__int128_t mid=(L+R)/2;
if(x+mid*(mid+1)/2>0)R=mid;
else L=mid;
}
// cout << (ll)L << " " << (ll)R;
__int128_t x_R=x+R*(R+1)/2;
if((n-R)%2==0){
__int128_t ans=x_R+(n-R)/2;
return ans;
}
else{
__int128_t ans=x_R-R-1-(n-R)/2;
return ans;
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll x,n;cin >> x >> n;
if(x==0){
if(n%2==0)cout << -n/2;
else cout << (n+1)/2;
}
else if(x>0)cout << solve_posi(x,n);
else cout << solve_nega(x,n);
}