【題解】AtCoder ABC 175C – Walking Takahashi

【題目敘述】https://atcoder.jp/contests/abc175/tasks/abc175_c

#include <iostream>
using namespace std;

long long n, k, d;

int main() {
    cin >> n >> k >> d;
    long long tmp = min(abs(n)/d, k);
    if (n < 0) n += d*tmp;
    else n -= d*tmp;
    k -= tmp;
    k %= 2;
    if (k){
        if (n < 0) n += d;
        else n -= d;
    }
    cout << abs(n) << "\n";
}

分享本文 Share with friends