Submission #1041202


Source Code Expand

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;


const ll INF = (ll)1e18;

ll mabs(ll a) {
    return a > 0 ? a : -a;
}

ll go(ll x, ll y) {
    if (x <= y)
        return y - x;
    return INF;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    ll x, y;
    cin >> x >> y;
    if (y == 0) {
        if (x < 0) {
            cout << mabs(x) << endl;
            return 0;
        }
        else {
            cout << mabs(x) + 1 << endl;
            return 0;
        }
    }
    ll res = INF;
    for (int s1 = 0; s1 < 2; s1++)
        for (int s2 = 0; s2 < 2; s2++) {
            ll curx = x;
            ll cury = y;
            ll cur = 0;
            if (s1) {
                curx = -curx;
                cur++;
            }      
            if (s2) {
                cury = -cury;
                cur++;
            }
            cur += go(curx, cury);
            res = min(res, cur);              
        }
    cout << res << endl;
}       

Submission Info

Submission Time
Task A - Simple Calculator
User kraskevich
Language C++14 (GCC 5.4.1)
Score 300
Code Size 1082 Byte
Status AC
Exec Time 48 ms
Memory 764 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 300 / 300
Status
AC × 3
AC × 14
Set Name Test Cases
Sample 0_00.txt, 0_01.txt, 0_02.txt
All 0_00.txt, 0_01.txt, 0_02.txt, 1_00.txt, 1_01.txt, 1_02.txt, 1_03.txt, 1_04.txt, 1_05.txt, 1_06.txt, 1_07.txt, 1_08.txt, 1_09.txt, 1_10.txt
Case Name Status Exec Time Memory
0_00.txt AC 48 ms 764 KB
0_01.txt AC 3 ms 256 KB
0_02.txt AC 2 ms 256 KB
1_00.txt AC 3 ms 256 KB
1_01.txt AC 3 ms 256 KB
1_02.txt AC 2 ms 256 KB
1_03.txt AC 2 ms 256 KB
1_04.txt AC 3 ms 256 KB
1_05.txt AC 2 ms 256 KB
1_06.txt AC 3 ms 256 KB
1_07.txt AC 3 ms 256 KB
1_08.txt AC 2 ms 256 KB
1_09.txt AC 3 ms 256 KB
1_10.txt AC 3 ms 256 KB