답안 #121090

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
121090 2019-06-26T05:38:22 Z tri 이상한 기계 (APIO19_strange_device) C++14
20 / 100
2754 ms 16932 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;

#define pb push_back
#define f first
#define s second

ll N, A, B;

int main() {
    cin >> N >> A >> B;
    ll gcd = __gcd(A, B + 1);
    ll AP = A / gcd;

    if (AP > (ll) 1e18 / B) {
        // period is so big it won't matter
        ll ans = 0;
        for (int i = 0; i < N; i++) {
            ll l, r;
            cin >> l >> r;
            ans += (r - l + 1);
        }
        cout << ans << endl;
        return 0;
    }

    ll P = AP * B;

    vector<pi> delts;

    for (int i = 0; i < N; i++) {
        ll l, r;
        cin >> l >> r;
        if (r - l + 1 >= P) {
            cout << P << endl;
            return 0;
        }

        l %= P;
        r %= P;

        if (l <= r) {
            delts.pb({l, +1});
            delts.pb({r + 1, -1});
        } else {
            delts.pb({l, +1});
            delts.pb({P, -1});
            delts.pb({0, +1});
            delts.pb({r + 1, -1});
        }
    }

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

    int cAct = 0;
    ll ans = 0;
    for (int i = 0; i < delts.size(); i++) {
        cAct += delts[i].s;
        if (i + 1 < delts.size()) {
            ll dist = delts[i + 1].f - delts[i].f;
            if (cAct > 0) {
                ans += dist;
            }
        }
    }
    cout << ans << endl;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:66:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < delts.size(); i++) {
                     ~~^~~~~~~~~~~~~~
strange_device.cpp:68:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (i + 1 < delts.size()) {
             ~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 29 ms 632 KB Output is correct
3 Correct 29 ms 632 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 252 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 29 ms 632 KB Output is correct
17 Correct 284 ms 2508 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 256 KB Output is correct
3 Correct 2 ms 424 KB Output is correct
4 Correct 2 ms 256 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 348 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 380 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 1938 ms 16932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2754 ms 16900 KB Output is correct
3 Incorrect 2680 ms 16844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2754 ms 16900 KB Output is correct
3 Incorrect 2680 ms 16844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 2754 ms 16900 KB Output is correct
3 Incorrect 2680 ms 16844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 282 ms 2468 KB Output is correct
3 Incorrect 274 ms 2644 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 252 KB Output is correct
2 Correct 29 ms 632 KB Output is correct
3 Correct 29 ms 632 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 256 KB Output is correct
6 Correct 2 ms 380 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 256 KB Output is correct
9 Correct 2 ms 252 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 29 ms 632 KB Output is correct
17 Correct 284 ms 2508 KB Output is correct
18 Correct 2 ms 256 KB Output is correct
19 Correct 2 ms 256 KB Output is correct
20 Correct 2 ms 256 KB Output is correct
21 Correct 2 ms 424 KB Output is correct
22 Correct 2 ms 256 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 348 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 380 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 1938 ms 16932 KB Output is correct
29 Correct 4 ms 376 KB Output is correct
30 Correct 2754 ms 16900 KB Output is correct
31 Incorrect 2680 ms 16844 KB Output isn't correct
32 Halted 0 ms 0 KB -