結果

問題 No.3048 Swing
ユーザー ゼリトキ
提出日時 2025-03-07 21:27:50
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 802 bytes
コンパイル時間 1,964 ms
コンパイル使用メモリ 160,368 KB
実行使用メモリ 8,608 KB
最終ジャッジ日時 2025-03-07 21:28:15
合計ジャッジ時間 24,133 ms
ジャッジサーバーID
(参考情報)
judge4 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 55 WA * 3
権限があれば一括ダウンロードができます

ソースコード

diff #

#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;
    }
    else if(x<0){
        while(x<0){
            x+=cnt;
            if(cnt==n){
                cout<<x<<endl;
                return 0;
            }
            cnt++;
        }
        x2=x+cnt;
    }
    else{
        x=0;
        x2=1;
    }
    if((n-cnt)%2==0){
        cout<<x2+(n-cnt)/2<<endl;
    }
    else{
        cout<<x-(n-cnt+1)/2<<endl;
    }
}
0