Submission #597801

# Submission time Handle Problem Language Result Execution time Memory
597801 2022-07-16T22:20:58 Z Ozy Strange Device (APIO19_strange_device) C++17
65 / 100
606 ms 33396 KB
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define lli unsigned 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 << 60)

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 = __gcd(a,b+1);
    //debug(k);
    k = a/k;

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

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

        if (x == y) {
            x %= mult;
            orden.push_back({x,1});
            orden.push_back({x,2});
            continue;
        }

        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;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:7:39: warning: comparison of integer expressions of different signedness: 'int' and 'long long unsigned int' [-Wsign-compare]
    7 | #define rep(i,a,b) for(int i = (a); i <= (b); i++)
      |                                       ^
strange_device.cpp:28:5: note: in expansion of macro 'rep'
   28 |     rep(i,1,n) {
      |     ^~~
strange_device.cpp:58:21: warning: comparison of integer expressions of different signedness: 'long long unsigned int' and 'int' [-Wsign-compare]
   58 |             if (ini == -1) ini = act.first;
      |                 ~~~~^~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 5 ms 856 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 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 0 ms 212 KB Output is correct
16 Correct 5 ms 856 KB Output is correct
17 Correct 50 ms 4520 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 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 458 ms 33200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 463 ms 33180 KB Output is correct
3 Correct 491 ms 33396 KB Output is correct
4 Correct 447 ms 33288 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 463 ms 33180 KB Output is correct
3 Correct 491 ms 33396 KB Output is correct
4 Correct 447 ms 33288 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 453 ms 33192 KB Output is correct
7 Correct 444 ms 33288 KB Output is correct
8 Correct 455 ms 33300 KB Output is correct
9 Correct 525 ms 33164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 463 ms 33180 KB Output is correct
3 Correct 491 ms 33396 KB Output is correct
4 Correct 447 ms 33288 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 43 ms 4508 KB Output is correct
7 Correct 44 ms 4488 KB Output is correct
8 Correct 42 ms 4508 KB Output is correct
9 Correct 42 ms 4556 KB Output is correct
10 Correct 42 ms 4532 KB Output is correct
11 Correct 51 ms 4556 KB Output is correct
12 Correct 42 ms 4500 KB Output is correct
13 Correct 48 ms 4548 KB Output is correct
14 Correct 43 ms 4496 KB Output is correct
15 Correct 60 ms 4480 KB Output is correct
16 Correct 52 ms 4512 KB Output is correct
17 Correct 45 ms 4532 KB Output is correct
18 Correct 460 ms 33284 KB Output is correct
19 Correct 430 ms 33200 KB Output is correct
20 Correct 531 ms 33188 KB Output is correct
21 Correct 49 ms 4480 KB Output is correct
22 Correct 37 ms 4576 KB Output is correct
23 Correct 124 ms 16780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 59 ms 4448 KB Output is correct
3 Correct 47 ms 4556 KB Output is correct
4 Correct 606 ms 33256 KB Output is correct
5 Correct 48 ms 4556 KB Output is correct
6 Correct 47 ms 4520 KB Output is correct
7 Correct 50 ms 4528 KB Output is correct
8 Correct 49 ms 4556 KB Output is correct
9 Correct 45 ms 4532 KB Output is correct
10 Correct 49 ms 4556 KB Output is correct
11 Correct 52 ms 4544 KB Output is correct
12 Correct 45 ms 4480 KB Output is correct
13 Correct 50 ms 4544 KB Output is correct
14 Correct 519 ms 33180 KB Output is correct
15 Correct 51 ms 4556 KB Output is correct
16 Correct 421 ms 33252 KB Output is correct
17 Correct 452 ms 33176 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 5 ms 856 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 0 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 0 ms 212 KB Output is correct
16 Correct 5 ms 856 KB Output is correct
17 Correct 50 ms 4520 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Incorrect 0 ms 212 KB Output isn't correct
21 Halted 0 ms 0 KB -