답안 #258392

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
258392 2020-08-05T21:17:19 Z DS007 이상한 기계 (APIO19_strange_device) C++14
35 / 100
771 ms 33744 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, a, b;

bool overflow(int x, int y) {
    int result = x * y;
    return result / x != y;
}

int sum() {
    int ans = 0;
    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;
        ans += r - l + 1;
    }
    return ans;
}

int solveTestCase() {
    cin >> n >> a >> b;

    int temp = a / __gcd(a, b + 1);
    assert(a % __gcd(a, b + 1) == 0);
    if (overflow(temp, b))
        return cout << sum(), 0;

    temp *= b;
    //cerr << temp << "\n";
    vector<pair<int, int>> v;

    for (int i = 0; i < n; i++) {
        int l, r;
        cin >> l >> r;

        if (r - l >= temp)
            return cout << temp, 0;

        if (l % temp <= r % temp)
            v.emplace_back(l % temp, 1), v.emplace_back(r % temp + 1, 2);
        else
            v.emplace_back(l % temp, 1), v.emplace_back(temp, 2), v.emplace_back(0, 1), v.emplace_back(r % temp + 1, 2);
    }

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

    int ans = 0, d = 0, last = 0;
    for (auto i : v) {
        if (d == 0)
            last = i.first;

        if (i.second == 1)
            d++;
        else
            d--;

        assert(d >= 0);
        if (d == 0)
            ans += i.first - last;
    }

    cout << ans;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int t = 1;
    //cin >> t;
    while (t--)
        solveTestCase();
}


Compilation message

strange_device.cpp: In function 'long long int solveTestCase()':
strange_device.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 7 ms 1280 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1280 KB Output is correct
17 Correct 69 ms 4844 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Incorrect 0 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 417 ms 33600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 623 ms 33600 KB Output is correct
3 Correct 640 ms 33728 KB Output is correct
4 Correct 618 ms 33660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 623 ms 33600 KB Output is correct
3 Correct 640 ms 33728 KB Output is correct
4 Correct 618 ms 33660 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 642 ms 33600 KB Output is correct
7 Correct 625 ms 33744 KB Output is correct
8 Correct 608 ms 33600 KB Output is correct
9 Correct 705 ms 33600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 623 ms 33600 KB Output is correct
3 Correct 640 ms 33728 KB Output is correct
4 Correct 618 ms 33660 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 61 ms 4844 KB Output is correct
7 Correct 66 ms 4844 KB Output is correct
8 Correct 58 ms 4844 KB Output is correct
9 Correct 60 ms 4852 KB Output is correct
10 Correct 60 ms 4844 KB Output is correct
11 Correct 63 ms 4844 KB Output is correct
12 Correct 59 ms 4844 KB Output is correct
13 Correct 65 ms 4844 KB Output is correct
14 Correct 57 ms 4844 KB Output is correct
15 Correct 72 ms 4844 KB Output is correct
16 Correct 65 ms 4852 KB Output is correct
17 Correct 60 ms 4844 KB Output is correct
18 Correct 625 ms 33600 KB Output is correct
19 Correct 599 ms 33600 KB Output is correct
20 Correct 763 ms 33600 KB Output is correct
21 Correct 69 ms 4844 KB Output is correct
22 Correct 62 ms 4844 KB Output is correct
23 Correct 173 ms 17108 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 65 ms 4852 KB Output is correct
3 Correct 66 ms 4844 KB Output is correct
4 Correct 771 ms 33568 KB Output is correct
5 Correct 65 ms 4844 KB Output is correct
6 Correct 66 ms 4844 KB Output is correct
7 Correct 65 ms 4852 KB Output is correct
8 Correct 68 ms 4844 KB Output is correct
9 Correct 68 ms 4848 KB Output is correct
10 Correct 69 ms 4852 KB Output is correct
11 Correct 67 ms 4864 KB Output is correct
12 Correct 62 ms 4836 KB Output is correct
13 Correct 69 ms 4840 KB Output is correct
14 Correct 718 ms 33528 KB Output is correct
15 Correct 70 ms 4808 KB Output is correct
16 Correct 597 ms 33728 KB Output is correct
17 Correct 618 ms 33600 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 6 ms 1280 KB Output is correct
3 Correct 7 ms 1280 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 0 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 0 ms 384 KB Output is correct
9 Correct 0 ms 384 KB Output is correct
10 Correct 0 ms 384 KB Output is correct
11 Correct 0 ms 384 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 6 ms 1280 KB Output is correct
17 Correct 69 ms 4844 KB Output is correct
18 Incorrect 1 ms 384 KB Output isn't correct