Submission #597794

# Submission time Handle Problem Language Result Execution time Memory
597794 2022-07-16T22:03:55 Z Ozy Strange Device (APIO19_strange_device) C++17
65 / 100
622 ms 40348 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define debug(a) cout << #a << " = " << a << endl
#define debugsl(a) cout << #a << " = " << a << ", "
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define repa(i,a,b) for(int i = (a); i >= (b); i--)

#define LIM (1ll << 62)

lli a,b,n,cont,x,y,mult,ini,res,k;
vector<pair<lli,lli> > orden;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n >> a >> b;
    k = a/__gcd(a,b+1);

    if (LIM/k < b) mult = LIM;
    else {
        mult = k*b;
    }

    rep(i,1,n) {
        cin >> x >> y;

        x %= mult;
        y %= mult;

        if (x > y) {
            orden.push_back({0,1});
            orden.push_back({mult-1,2});
        }
        orden.push_back({x,1});
        orden.push_back({y,2});
    }

    sort(orden.begin(), orden.end());

    ini = -1;
    cont = 0;
    res = 0;
    for (auto act:orden) {

        if (act.second == 1) {
            cont++;
            if (ini == -1) ini = act.first;
        }
        else cont--;

        if (cont == 0) {
            res += (act.first - ini) + 1;
            ini = -1;
        }
    }

    cout << res;
}

# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 5 ms 984 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 6 ms 1292 KB Output is correct
17 Correct 64 ms 7284 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 1 ms 320 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 312 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 396 ms 33304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 532 ms 33400 KB Output is correct
3 Correct 496 ms 33380 KB Output is correct
4 Correct 489 ms 38664 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 532 ms 33400 KB Output is correct
3 Correct 496 ms 33380 KB Output is correct
4 Correct 489 ms 38664 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 542 ms 38728 KB Output is correct
7 Correct 522 ms 38840 KB Output is correct
8 Correct 509 ms 38892 KB Output is correct
9 Correct 622 ms 38900 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 532 ms 33400 KB Output is correct
3 Correct 496 ms 33380 KB Output is correct
4 Correct 489 ms 38664 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 47 ms 7204 KB Output is correct
7 Correct 54 ms 7212 KB Output is correct
8 Correct 50 ms 7280 KB Output is correct
9 Correct 51 ms 7260 KB Output is correct
10 Correct 62 ms 7212 KB Output is correct
11 Correct 53 ms 7300 KB Output is correct
12 Correct 45 ms 7236 KB Output is correct
13 Correct 52 ms 7180 KB Output is correct
14 Correct 47 ms 7228 KB Output is correct
15 Correct 68 ms 7224 KB Output is correct
16 Correct 62 ms 7284 KB Output is correct
17 Correct 56 ms 7228 KB Output is correct
18 Correct 492 ms 38872 KB Output is correct
19 Correct 522 ms 38672 KB Output is correct
20 Correct 583 ms 38696 KB Output is correct
21 Correct 58 ms 7228 KB Output is correct
22 Correct 43 ms 7232 KB Output is correct
23 Correct 138 ms 26628 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 50 ms 4652 KB Output is correct
3 Correct 54 ms 4656 KB Output is correct
4 Correct 598 ms 33388 KB Output is correct
5 Correct 48 ms 4676 KB Output is correct
6 Correct 49 ms 4676 KB Output is correct
7 Correct 49 ms 4596 KB Output is correct
8 Correct 68 ms 4640 KB Output is correct
9 Correct 50 ms 4636 KB Output is correct
10 Correct 52 ms 4620 KB Output is correct
11 Correct 48 ms 4724 KB Output is correct
12 Correct 47 ms 4680 KB Output is correct
13 Correct 52 ms 4592 KB Output is correct
14 Correct 561 ms 33404 KB Output is correct
15 Correct 52 ms 4664 KB Output is correct
16 Correct 445 ms 38684 KB Output is correct
17 Correct 497 ms 40348 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 5 ms 984 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 324 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 1 ms 316 KB Output is correct
16 Correct 6 ms 1292 KB Output is correct
17 Correct 64 ms 7284 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Incorrect 1 ms 320 KB Output isn't correct
21 Halted 0 ms 0 KB -