QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#355498#8111. Coachesucup-team004WA 1ms3688kbC++202.1kb2024-03-16 18:38:022024-03-16 18:38:04

Judging History

This is the latest submission verdict.

  • [2024-03-16 18:38:04]
  • Judged
  • Verdict: WA
  • Time: 1ms
  • Memory: 3688kb
  • [2024-03-16 18:38:02]
  • Submitted

answer

#include <bits/stdc++.h>

using i64 = long long;

i64 f(i64 a, i64 b, i64 l, i64 r) {
    if (l == 0) {
        return 0;
    }
    if (a == 0) {
        return -1;
    }
    i64 v = (l + a - 1) / a;
    if (v * a <= r) {
        return v;
    }
    v = f(b, a % b, a - r % a, a - l % a);
    if (v == -1) {
        return -1;
    }
    return (v * b + l + a - 1) / a;
}

bool get1(i64 a, i64 x, i64 n, i64 b, i64 y) {
    if (x >= n) {
        return false;
    }
    if (y == 0) {
        return true;
    }
    std::cerr << a << " " << x << " " << n << " " << b << " " << y << "\n";
    i64 l = (y - x % b + b) % b;
    i64 r = (-x % b + b) % b;
    i64 k = (n - 1 - x) / a;
    if (l < r) {
        i64 v = f(a, b, l, r - 1);
        if (v != -1 && v <= k) {
            return true;
        }
    } else {
        if (l < b) {
            i64 v = f(a, b, l, b - 1);
            if (v != -1 && v <= k) {
                return true;
            }
        }
        if (r > 0) {
            i64 v = f(a, b, 0, r - 1);
            if (v != -1 && v <= k) {
                return true;
            }
        }
    }
    return false;
}

i64 get(i64 n, int a, int b) {
    int g = std::gcd(a, b);
    if (g != 1) {
        return get(n / g, a / g, b / g);
    }
    i64 res = n / a + n / b - 2 * (n / a / b);
    i64 na = n % a;
    i64 nb = n % b;
    i64 nab = n % (1LL * a * b);
    if (na < nab || nb < nab) {
        res--;
    }
    if (get1(a, na, nab, b, nb)
        || get1(b, nb, nab, a, na)) {
        res--;
    }
    return res;
}

int t = 0;
int ok = 0;

void solve() {
    i64 n;
    int a, b;
    std::cin >> n >> a >> b;
    t++;

    i64 bad = get(n, a, b);

    if (t == 2799) {
        std::cout << n << " " << a << " " << b << "\n";
        std::exit(0);
    }
    if (ok) std::cout << n - bad << "\n";
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    
    int t;
    std::cin >> t;

    if (t < 2000) {
        ok = 1;
    }

    while (t--) {
        solve();
    }    

    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3688kb

input:

2
5 2 3
10 7 2

output:

3
6

result:

ok 2 number(s): "3 6"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3628kb

input:

1728
7 6 3
10 12 1
6 2 7
8 4 10
11 10 5
1 6 8
3 3 5
9 2 6
11 1 5
1 1 8
7 3 6
6 10 9
2 1 7
3 4 7
8 3 4
4 5 9
9 4 3
6 2 8
11 4 1
6 8 4
11 1 8
9 11 2
9 6 1
5 3 8
7 1 8
7 11 12
3 9 1
2 12 6
7 2 6
5 11 10
9 5 3
3 6 2
7 5 5
12 4 3
7 8 2
8 11 11
10 1 10
5 1 7
9 1 7
8 1 6
8 4 6
5 5 11
12 3 7
3 6 8
6 3 11
6 ...

output:

6
1
4
7
10
1
3
7
3
1
6
6
1
3
6
4
6
4
3
6
2
6
2
5
1
7
1
2
5
5
7
3
7
7
5
8
1
1
2
2
7
5
9
3
5
4
11
3
1
1
12
3
7
1
5
5
12
2
10
1
9
5
1
2
10
6
3
12
1
12
10
6
1
7
2
5
10
7
11
9
2
3
1
6
9
8
2
5
3
3
10
1
9
11
2
8
8
7
7
9
3
1
2
3
1
3
3
9
4
6
8
1
12
6
3
10
1
1
9
12
6
1
9
11
1
6
2
3
12
7
6
6
9
11
9
1
2
5
2
4
4...

result:

ok 1728 numbers

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3688kb

input:

97336
24 2 23
23 31 33
11 38 46
13 19 11
44 45 5
41 37 42
44 16 29
31 33 17
34 26 39
16 17 20
42 15 36
30 10 2
37 42 3
1 41 45
10 9 5
8 33 5
21 44 8
2 30 15
42 32 32
19 22 43
22 46 5
34 1 30
12 4 12
23 43 6
42 2 39
16 38 20
16 19 5
43 8 13
11 24 4
41 20 31
29 42 31
42 13 41
39 5 25
10 11 1
39 35 32
...

output:

35 8 9

result:

wrong answer 1st numbers differ - expected: '13', found: '35'