CSES - Putka Open 2015 – 1/6 - Results
Submission details
Task:Jakkara
Sender:
Submission time:2015-07-18 18:52:44 +0300
Language:C++
Status:READY
Result:25
Feedback
groupverdictscore
#10
#2ACCEPTED25
#30
Test results
testverdicttimegroup
#1ACCEPTED0.08 s1details
#20.08 s1details
#30.08 s1details
#4ACCEPTED0.09 s1details
#5ACCEPTED0.08 s1details
#6ACCEPTED0.09 s2details
#7ACCEPTED0.08 s2details
#8ACCEPTED0.09 s2details
#9ACCEPTED0.08 s2details
#10ACCEPTED0.08 s2details
#11--3details
#120.07 s3details
#13--3details
#14--3details
#15ACCEPTED0.09 s3details

Code

#include <iostream>
#include <cmath>

using namespace std;

long long a, b, c, d;

long long chg(long long v) {
    return abs(a-v)+abs(b-v)+abs(c-v)+abs(d-v);
}


int main(int argc, char const *argv[]) {
    cin >> a;
    cin >> b;
    cin >> c;
    cin >> d;

    long long mn = a;
    long long mx = a;
    if (b < mn) {mn = b;}
    if (c < mn) {mn = c;}
    if (d < mn) {mn = d;}
    if (b > mx) {mx = b;}
    if (c > mx) {mx = c;}
    if (d > mx) {mx = d;}

    if (mn == mx) {
        cout << 0 << endl;
        return 0;
    }

    long long res = chg(mn);
    long long tmp = 0;

    long long up = (mx+mn)/2;
    long long down = (mx+mn)/2-1;

    long long pres_up = -1;
    long long pres_down = -1;

    while (up != -1 && down != -1) {
        if (up != -1) {
            tmp = chg(up);
            if (tmp >= pres_up && pres_up!=-1) {
                up = -1;
            }
            else {
                pres_up = tmp;
                if (tmp < res) {
                    res = tmp;
                }
                up++;
                if (up >= mx) {
                    up = -1;
                }
            }
        }
        if (down != -1) {
            tmp = chg(down);
            if (tmp >= pres_down && pres_down!=-1) {
                down = -1;
            }
            else {
                pres_up = tmp;
                if (tmp < res) {
                    res = tmp;
                }
            }
            down--;
            if (down <= mn) {
                down = -1;
            }
        }
    }

    cout << res << endl;
    return 0;
}

Test details

Test 1

Group: 1

Verdict: ACCEPTED

input
2 4 2 1

correct output
3

user output
3

Test 2

Group: 1

Verdict:

input
4 4 5 1

correct output
4

user output
6

Test 3

Group: 1

Verdict:

input
1 3 3 3

correct output
2

user output
4

Test 4

Group: 1

Verdict: ACCEPTED

input
4 5 2 1

correct output
6

user output
6

Test 5

Group: 1

Verdict: ACCEPTED

input
1 2 3 4

correct output
4

user output
4

Test 6

Group: 2

Verdict: ACCEPTED

input
755 181 899 550

correct output
923

user output
923

Test 7

Group: 2

Verdict: ACCEPTED

input
415 158 928 660

correct output
1015

user output
1015

Test 8

Group: 2

Verdict: ACCEPTED

input
8 786 277 786

correct output
1287

user output
1287

Test 9

Group: 2

Verdict: ACCEPTED

input
740 537 892 1000

correct output
615

user output
615

Test 10

Group: 2

Verdict: ACCEPTED

input
805 794 799 591

correct output
219

user output
219

Test 11

Group: 3

Verdict:

input
918046201 377309798 763092200 ...

correct output
753184325

user output
(empty)

Test 12

Group: 3

Verdict:

input
185264934 19222757 522094385 9...

correct output
595938743

user output
741888867

Test 13

Group: 3

Verdict:

input
727047841 260674959 553589480 ...

correct output
678802024

user output
(empty)

Test 14

Group: 3

Verdict:

input
769070856 877861912 488304785 ...

correct output
614008750

user output
(empty)

Test 15

Group: 3

Verdict: ACCEPTED

input
1 1 1 1000000000

correct output
999999999

user output
999999999