結果
| 問題 |
No.3048 Swing
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2025-03-07 22:34:47 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
RE
|
| 実行時間 | - |
| コード長 | 795 bytes |
| コンパイル時間 | 1,918 ms |
| コンパイル使用メモリ | 194,492 KB |
| 実行使用メモリ | 8,612 KB |
| 最終ジャッジ日時 | 2025-03-07 22:35:13 |
| 合計ジャッジ時間 | 6,709 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 29 WA * 3 RE * 26 |
ソースコード
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
template<class T> bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;}
template<class T> bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;}
void Solve(){
ll X,N;
cin>>X>>N;
ll ok=0,ng=sqrt(2*X)+10;
while(ng-ok>1){
ll mid=(ok+ng)/2;
if(mid*(mid+1)/2<=X)ok=mid;
else ng=mid;
}
if(ok>=N){
X-=N*(N+1)/2;
cout<<X<<"\n";
}else{
X-=ok*(ok+1)/2;
assert(X>=0);
N-=ok;
if(N%2==0)cout<<X+N/2<<"\n";
else cout<<X-(ok+1)-N/2<<"\n";
}
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
Solve();
}