답안 #222716

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
222716 2020-04-13T21:43:07 Z shart23 이상한 기계 (APIO19_strange_device) C++14
0 / 100
543 ms 32612 KB
#include <bits/stdc++.h>

#define int long long
#define endl "\n"

using namespace std;

int clever(int n, int a, int b, vector<pair<int, int>> &seg) {
    long double k1 = a * (long double) (b / __gcd(a, b));
    int k = (int) 1e18 + 1;
    if (k1 <= 1e18) {
        k = a / __gcd(a, b) * b;
    }
    vector<pair<int, int>> segs;
    for (int i = 0; i < n; i++) {
        int l = seg[i].first, r = seg[i].second;
        if (r - l + 1 >= k) {
            segs.emplace_back(0, k - 1);
            continue;
        }
        int l1 = l % k, r1 = r % k;
        if (r1 < l1) {
            segs.emplace_back(0, r1);
            segs.emplace_back(l1, k - 1);
        } else {
            segs.emplace_back(l1, r1);
        }
    }
    sort(segs.begin(), segs.end());
    int mxr = -1;
    int res = 0;
    for (auto x : segs) {
        res += max(x.second - max(mxr, x.first - 1), 0LL);
        mxr = max(x.second, mxr);
    }
    return res;
}

int stupid(int n, int a, int b, vector<pair<int, int>> &seg) {
    set<pair<int, int>> ans;
    for (int i = 0; i < n; i++) {
        int l = seg[i].first, r = seg[i].second;
        for (int j = l; j <= r; j++) {
            ans.insert({(j + j / b) % a, j % b});
        }
    }
    return ans.size();
}

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>> seg(n);
    for (auto &x : seg) {
        cin >> x.first >> x.second;
    }
    cout << clever(n, a, b, seg) << endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 10 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Incorrect 6 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 5 ms 384 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 543 ms 32608 KB Output is correct
3 Incorrect 538 ms 32612 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 543 ms 32608 KB Output is correct
3 Incorrect 538 ms 32612 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 543 ms 32608 KB Output is correct
3 Incorrect 538 ms 32612 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 59 ms 4208 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Incorrect 10 ms 768 KB Output isn't correct
3 Halted 0 ms 0 KB -