CSES - BAPC 2015 - Results
Submission details
Task:Wipe Your Whiteboards
Sender:Qianyun Guo
Submission time:2017-10-17 20:03:43 +0300
Language:C++
Status:READY
Result:ACCEPTED
Test results
testverdicttime
#1ACCEPTED0.04 sdetails
#2ACCEPTED0.04 sdetails
#3ACCEPTED0.05 sdetails
#4ACCEPTED0.04 sdetails

Code

#include<bits/stdc++.h>
using namespace std;

int T;
long long r, s, q;
long long x, y;

long long gcd(long long a, long long b) {
    return b == 0 ? a : gcd(b, a % b);
}

// find x, y st. ax + by = gcd(a, b)
long long ext_euclid(long long a, long long b, long long *x, long long *y) {
    if (b == 0) {
        *x = 1;
        *y = 0;
        return a;
    }

    long long x1, y1;
    long long g = ext_euclid(b,  a % b, &x1, &y1);

    *x = y1; 
    *y = x1 - (a / b) * y1;
    return g;
}

long long f(long long x, long long y) {
    if (x < 0) 
        return x/y;
    return (x + y - 1) / y;
}

int main() {
    cin >> T;
    while (T--) {
        cin >> r >> s >> q;
        long long g = ext_euclid(r, -s, &x, &y);
        x *= q/g;
        y *= -q/g;
        long long u = max(f(1-x, -s/g), f(1-y, r/g));
        cout << x + u*(-s/g) << " " << y + u*(r/g) << endl;
    }
    
    return 0;
}

Test details

Test 1

Verdict: ACCEPTED

input
243
2 -2 2
2 -2 4
2 -2 6
2 -3 1
...

correct output
2 1
3 1
4 1
2 1
4 2
...

user output
2 1
3 1
4 1
2 1
4 2
...

Test 2

Verdict: ACCEPTED

input
100
37519548 -81935448 71983128
12441731 -99044784 98614084
99608264 -5674831 20315968
7288065 -67360366 2498082
...

correct output
4207392 1926631
64596284 8114405
3401796 59710496
21767778 2355168
4956464 1069368
...

user output
4207392 1926631
64596284 8114405
3401796 59710496
21767778 2355168
4956464 1069368
...

Test 3

Verdict: ACCEPTED

input
50
6387854 -19137400 28428
8306928 -18469944 46440
7145568 -427420 25800
4298766 -20849718 63474
...

correct output
48282 16116
37565 16895
2265 37866
11427 2356
43311 40524
...

user output
48282 16116
37565 16895
2265 37866
11427 2356
43311 40524
...

Test 4

Verdict: ACCEPTED

input
6
2 -2 2
2 -2 10
3 -2 1
3 -2 4124
...

correct output
2 1
6 1
1 1
1376 2
1 2
...

user output
2 1
6 1
1 1
1376 2
1 2
...