답안 #217036

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
217036 2020-03-28T18:14:54 Z sevlll 이상한 기계 (APIO19_strange_device) C++17
35 / 100
778 ms 49716 KB
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>

#define pb push_back
#define int long long
#define str string
using namespace std;
const int M = 1e9 + 7;

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n, a, b;
    cin >> n >> a >> b;
    vector<pair<int, int>> pr(n);
    for (int i = 0; i < n; i++) cin >> pr[i].first >> pr[i].second;
    int g = gcd(a, b + 1);
    a /= g;
    int num = a * b;
    if (n == 1) {
        int l = pr[0].first, r = pr[0].second;
        if (r - l >= num - 1) {
            cout << num;
        } else {
            if (l == r) {
                cout << 1;
            } else {
                l %= num;
                r %= num;
                if (l <= r) {
                    cout << r - l + 1;
                } else {
                    cout << (r - l + 1) + (int) num;
                }
            }
        }
        return 0;
    }
    vector<pair<int, int>> ev;
    for (auto p : pr) {
        int l = p.first, r = p.second;
        if (r - l >= num - 1) {
            cout << (int) num;
            return 0;
        }
        l %= num;
        r %= num;
        if (r < l) {
            ev.pb({l, 1});
            ev.pb({num, -1});
            ev.pb({0, 1});
            ev.pb({r + 1, -1});
        } else {
            ev.pb({l, 1});
            ev.pb({r + 1, -1});
        }
    }
    sort(ev.begin(), ev.end());
    int bal = 0;
    int last = 0;
    int ans = 0;
    for (auto p : ev) {
        int x = p.first;
        int type = p.second;
        if (bal) {
            ans += (x - last);
        }
        last = x;
        bal += type;
    }
    cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 11 ms 1536 KB Output is correct
3 Correct 14 ms 1536 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1536 KB Output is correct
17 Correct 76 ms 6892 KB Output is correct
18 Incorrect 4 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 4 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Incorrect 4 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 512 KB Output is correct
5 Correct 448 ms 49620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 647 ms 49620 KB Output is correct
3 Correct 648 ms 49596 KB Output is correct
4 Correct 635 ms 49716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 647 ms 49620 KB Output is correct
3 Correct 648 ms 49596 KB Output is correct
4 Correct 635 ms 49716 KB Output is correct
5 Correct 4 ms 384 KB Output is correct
6 Correct 658 ms 49624 KB Output is correct
7 Correct 638 ms 49620 KB Output is correct
8 Correct 646 ms 49620 KB Output is correct
9 Correct 746 ms 49620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 647 ms 49620 KB Output is correct
3 Correct 648 ms 49596 KB Output is correct
4 Correct 635 ms 49716 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 73 ms 6764 KB Output is correct
7 Correct 66 ms 6768 KB Output is correct
8 Correct 64 ms 6764 KB Output is correct
9 Correct 68 ms 6764 KB Output is correct
10 Correct 62 ms 6764 KB Output is correct
11 Correct 68 ms 6764 KB Output is correct
12 Correct 64 ms 6764 KB Output is correct
13 Correct 73 ms 6764 KB Output is correct
14 Correct 64 ms 6764 KB Output is correct
15 Correct 79 ms 6764 KB Output is correct
16 Correct 76 ms 6764 KB Output is correct
17 Correct 66 ms 6792 KB Output is correct
18 Correct 643 ms 49620 KB Output is correct
19 Correct 607 ms 49500 KB Output is correct
20 Correct 766 ms 49628 KB Output is correct
21 Correct 73 ms 6636 KB Output is correct
22 Correct 61 ms 6764 KB Output is correct
23 Correct 185 ms 22628 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 71 ms 6640 KB Output is correct
3 Correct 73 ms 6636 KB Output is correct
4 Correct 778 ms 49440 KB Output is correct
5 Correct 72 ms 6636 KB Output is correct
6 Correct 77 ms 6636 KB Output is correct
7 Correct 75 ms 6636 KB Output is correct
8 Correct 76 ms 6636 KB Output is correct
9 Correct 71 ms 6636 KB Output is correct
10 Correct 73 ms 6636 KB Output is correct
11 Correct 73 ms 6684 KB Output is correct
12 Correct 69 ms 6636 KB Output is correct
13 Correct 73 ms 6636 KB Output is correct
14 Correct 770 ms 49496 KB Output is correct
15 Correct 74 ms 6636 KB Output is correct
16 Correct 601 ms 49496 KB Output is correct
17 Correct 620 ms 49488 KB Output is correct
18 Incorrect 4 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 11 ms 1536 KB Output is correct
3 Correct 14 ms 1536 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 384 KB Output is correct
13 Correct 5 ms 384 KB Output is correct
14 Correct 5 ms 384 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1536 KB Output is correct
17 Correct 76 ms 6892 KB Output is correct
18 Incorrect 4 ms 384 KB Output isn't correct