답안 #120782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
120782 2019-06-25T13:14:15 Z PeppaPig 이상한 기계 (APIO19_strange_device) C++14
35 / 100
895 ms 33452 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);
        if(r - l + 1 >= cyc) v.emplace_back(0, 1), v.emplace_back(cyc, -1);
        else {
            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 ans = 0;
    for(int i = 0, cnt = 0; i < v.size(); ) {
        int j = i;
        for( ; v[i].x == v[j].x; j++) cnt += v[j].y;
        if(cnt) ans += v[j].x - v[i].x;
        i = j;
    }
    printf("%lld\n", ans);

    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:37:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 0, cnt = 0; i < v.size(); ) {
                             ~~^~~~~~~~~~
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);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 1012 KB Output is correct
3 Correct 9 ms 884 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 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 348 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 9 ms 1008 KB Output is correct
17 Correct 79 ms 4580 KB Output is correct
18 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 2 ms 256 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Runtime error 2 ms 376 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 504 ms 33336 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 688 ms 33268 KB Output is correct
3 Correct 715 ms 33252 KB Output is correct
4 Correct 710 ms 33236 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 688 ms 33268 KB Output is correct
3 Correct 715 ms 33252 KB Output is correct
4 Correct 710 ms 33236 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 714 ms 33364 KB Output is correct
7 Correct 690 ms 33352 KB Output is correct
8 Correct 696 ms 33216 KB Output is correct
9 Correct 814 ms 33264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 688 ms 33268 KB Output is correct
3 Correct 715 ms 33252 KB Output is correct
4 Correct 710 ms 33236 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 69 ms 4540 KB Output is correct
7 Correct 68 ms 4580 KB Output is correct
8 Correct 68 ms 4580 KB Output is correct
9 Correct 68 ms 4580 KB Output is correct
10 Correct 65 ms 4608 KB Output is correct
11 Correct 76 ms 4592 KB Output is correct
12 Correct 70 ms 4552 KB Output is correct
13 Correct 75 ms 4592 KB Output is correct
14 Correct 67 ms 4540 KB Output is correct
15 Correct 79 ms 4580 KB Output is correct
16 Correct 76 ms 4532 KB Output is correct
17 Correct 69 ms 4512 KB Output is correct
18 Correct 705 ms 33312 KB Output is correct
19 Correct 668 ms 33316 KB Output is correct
20 Correct 818 ms 33280 KB Output is correct
21 Correct 80 ms 4624 KB Output is correct
22 Correct 60 ms 4580 KB Output is correct
23 Correct 231 ms 16844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 376 KB Output is correct
2 Correct 76 ms 4524 KB Output is correct
3 Correct 76 ms 4580 KB Output is correct
4 Correct 895 ms 33260 KB Output is correct
5 Correct 74 ms 4580 KB Output is correct
6 Correct 74 ms 4620 KB Output is correct
7 Correct 75 ms 4580 KB Output is correct
8 Correct 78 ms 4584 KB Output is correct
9 Correct 73 ms 4580 KB Output is correct
10 Correct 79 ms 4620 KB Output is correct
11 Correct 76 ms 4580 KB Output is correct
12 Correct 67 ms 4708 KB Output is correct
13 Correct 82 ms 4560 KB Output is correct
14 Correct 808 ms 33240 KB Output is correct
15 Correct 79 ms 4580 KB Output is correct
16 Correct 670 ms 33452 KB Output is correct
17 Correct 684 ms 33280 KB Output is correct
18 Runtime error 2 ms 380 KB Execution killed with signal 11 (could be triggered by violating memory limits)
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 9 ms 1012 KB Output is correct
3 Correct 9 ms 884 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 2 ms 256 KB Output is correct
8 Correct 2 ms 256 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 348 KB Output is correct
13 Correct 2 ms 256 KB Output is correct
14 Correct 2 ms 256 KB Output is correct
15 Correct 2 ms 256 KB Output is correct
16 Correct 9 ms 1008 KB Output is correct
17 Correct 79 ms 4580 KB Output is correct
18 Runtime error 2 ms 504 KB Execution killed with signal 11 (could be triggered by violating memory limits)