結果

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

ソースコード

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{
        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;
    }
}
0