Submission #120779

# Submission time Handle Problem Language Result Execution time Memory
120779 2019-06-25T13:06:47 Z PeppaPig Strange Device (APIO19_strange_device) C++14
65 / 100
874 ms 33412 KB
#include <bits/stdc++.h>

#define long long long
#define pii pair<long, long>
#define x first
#define y second

using namespace std;

const int N = 1e6+5;

int n;
long A, B, cyc;
vector<pii> v;

int main() {
    scanf("%d %lld %lld", &n, &A, &B);
    cyc = A / __gcd(B+1, A);
    cyc *= B;

    for(int i = 1; i <= n; i++) {
        long l, r;
        scanf("%lld %lld", &l, &r);
        l %= cyc, r %= cyc;
        v.emplace_back(l, -1);
        v.emplace_back(r + 1, 1); 
        if(l > r) v.emplace_back(0, -1), v.emplace_back(cyc, 1);
    }
    sort(v.begin(), v.end());

    long pv = 0, cnt = 0, ans = 0;
    for(int i = 0; i < v.size(); i++) {
        if(cnt == 0) pv = v[i].x;
        cnt -= v[i].y;
        if(cnt == 0) ans += v[i].x - pv;
    }
    printf("%lld\n", ans);

    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:32:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0; i < v.size(); i++) {
                    ~~^~~~~~~~~~
strange_device.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d %lld %lld", &n, &A, &B);
     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld %lld", &l, &r);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 888 KB Output is correct
3 Correct 9 ms 1016 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 8 ms 1012 KB Output is correct
17 Correct 76 ms 4580 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Incorrect 2 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 296 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 516 ms 33228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 643 ms 33304 KB Output is correct
3 Correct 702 ms 33304 KB Output is correct
4 Correct 666 ms 33280 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 643 ms 33304 KB Output is correct
3 Correct 702 ms 33304 KB Output is correct
4 Correct 666 ms 33280 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 668 ms 33316 KB Output is correct
7 Correct 654 ms 33312 KB Output is correct
8 Correct 698 ms 33212 KB Output is correct
9 Correct 802 ms 33324 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 643 ms 33304 KB Output is correct
3 Correct 702 ms 33304 KB Output is correct
4 Correct 666 ms 33280 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 63 ms 4568 KB Output is correct
7 Correct 69 ms 4528 KB Output is correct
8 Correct 61 ms 4580 KB Output is correct
9 Correct 68 ms 4580 KB Output is correct
10 Correct 60 ms 4632 KB Output is correct
11 Correct 67 ms 4524 KB Output is correct
12 Correct 64 ms 4580 KB Output is correct
13 Correct 75 ms 4600 KB Output is correct
14 Correct 61 ms 4540 KB Output is correct
15 Correct 77 ms 4584 KB Output is correct
16 Correct 74 ms 4508 KB Output is correct
17 Correct 65 ms 4492 KB Output is correct
18 Correct 676 ms 33236 KB Output is correct
19 Correct 652 ms 33264 KB Output is correct
20 Correct 843 ms 33276 KB Output is correct
21 Correct 81 ms 4580 KB Output is correct
22 Correct 60 ms 4580 KB Output is correct
23 Correct 225 ms 16936 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 73 ms 4580 KB Output is correct
3 Correct 75 ms 4580 KB Output is correct
4 Correct 874 ms 33244 KB Output is correct
5 Correct 74 ms 4552 KB Output is correct
6 Correct 74 ms 4580 KB Output is correct
7 Correct 73 ms 4580 KB Output is correct
8 Correct 76 ms 4580 KB Output is correct
9 Correct 72 ms 4504 KB Output is correct
10 Correct 77 ms 4624 KB Output is correct
11 Correct 73 ms 4580 KB Output is correct
12 Correct 69 ms 4580 KB Output is correct
13 Correct 77 ms 4580 KB Output is correct
14 Correct 786 ms 33412 KB Output is correct
15 Correct 77 ms 4580 KB Output is correct
16 Correct 640 ms 33236 KB Output is correct
17 Correct 681 ms 33352 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 888 KB Output is correct
3 Correct 9 ms 1016 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 348 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 256 KB Output is correct
11 Correct 2 ms 256 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 8 ms 1012 KB Output is correct
17 Correct 76 ms 4580 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Incorrect 2 ms 256 KB Output isn't correct
21 Halted 0 ms 0 KB -