結果
| 問題 |
No.3048 Swing
|
| コンテスト | |
| ユーザー |
ゼリトキ
|
| 提出日時 | 2025-03-07 21:31:17 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 985 ms / 2,000 ms |
| コード長 | 1,101 bytes |
| コンパイル時間 | 1,183 ms |
| コンパイル使用メモリ | 162,860 KB |
| 実行使用メモリ | 7,844 KB |
| 最終ジャッジ日時 | 2025-06-20 02:24:39 |
| 合計ジャッジ時間 | 22,709 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 62 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
cin.tie(0)->sync_with_stdio(0);
cout.tie(0);
long long x,n;
cin>>x>>n;
long long cnt=1;
long long x2;
if(x>0){
while(x>0){
x-=cnt;
if(cnt==n){
cout<<x<<endl;
return 0;
}
cnt++;
}
x2=x+cnt;
if((n-cnt)%2==0){
cout<<x2+(n-cnt)/2<<endl;
}
else{
cout<<x-(n-cnt+1)/2<<endl;
}
}
else if(x<0){
while(x<=0){
x+=cnt;
if(cnt==n){
cout<<x<<endl;
return 0;
}
cnt++;
}
x2=x-cnt;
if((n-cnt)%2==0){
cout<<x2-(n-cnt)/2<<endl;
}
else{
cout<<x+(n-cnt+1)/2<<endl;
}
}
else{
x=0;
x2=1;
if((n-cnt)%2==0){
cout<<x2+(n-cnt)/2<<endl;
}
else{
cout<<x-(n-cnt+1)/2<<endl;
}
}
}
ゼリトキ