답안 #554218

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
554218 2022-04-28T03:13:47 Z happypotato 이상한 기계 (APIO19_strange_device) C++17
65 / 100
1454 ms 33584 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
int gcd(int a, int b) {
    while (b) b ^= a ^= b ^= a %= b;
    return a;
}
void solve() {
    int n, a, b;
    cin >> n >> a >> b;
    priority_queue<pair<int, bool>, vector<pair<int, bool> >, greater<pair<int, bool> > > pq;
    int mod;
    if (log2(a) + log2(b) > log2(1e18)) mod = 2e18;
    else mod = a * b / gcd(a, b + 1);
    while (n--) {
        int l, r;
        cin >> l >> r;
        l %= mod; r %= mod;
        if (l > r) {
            pq.push({l, true});
            pq.push({mod, false});
            pq.push({0, true});
            pq.push({r + 1, false});
        } else {
            pq.push({l, true});
            pq.push({r + 1, false});
        }
    }
    int prev = 0, ans = 0;
    int cnt = 0;
    while (!pq.empty()) {
        pair<int, bool> cur = pq.top();
        pq.pop();
        if (cnt) ans += cur.first - prev;
        prev = cur.first;
        cnt += (cur.second ? 1 : -1);
    }
    cout << ans << endl;
}
signed main() {
    solve();
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 15 ms 1360 KB Output is correct
3 Correct 15 ms 1232 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 15 ms 1204 KB Output is correct
17 Correct 154 ms 6540 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 316 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 1034 ms 33256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1454 ms 33360 KB Output is correct
3 Correct 1420 ms 33344 KB Output is correct
4 Correct 1403 ms 33376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1454 ms 33360 KB Output is correct
3 Correct 1420 ms 33344 KB Output is correct
4 Correct 1403 ms 33376 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1416 ms 33456 KB Output is correct
7 Correct 1422 ms 33360 KB Output is correct
8 Correct 1402 ms 33584 KB Output is correct
9 Correct 1402 ms 33408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1454 ms 33360 KB Output is correct
3 Correct 1420 ms 33344 KB Output is correct
4 Correct 1403 ms 33376 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 150 ms 5944 KB Output is correct
7 Correct 146 ms 6492 KB Output is correct
8 Correct 143 ms 6548 KB Output is correct
9 Correct 141 ms 6472 KB Output is correct
10 Correct 144 ms 6444 KB Output is correct
11 Correct 146 ms 6460 KB Output is correct
12 Correct 143 ms 6176 KB Output is correct
13 Correct 144 ms 6552 KB Output is correct
14 Correct 155 ms 6460 KB Output is correct
15 Correct 142 ms 6432 KB Output is correct
16 Correct 139 ms 6380 KB Output is correct
17 Correct 155 ms 6384 KB Output is correct
18 Correct 1421 ms 33412 KB Output is correct
19 Correct 1431 ms 33348 KB Output is correct
20 Correct 1405 ms 33348 KB Output is correct
21 Correct 141 ms 5688 KB Output is correct
22 Correct 148 ms 5860 KB Output is correct
23 Correct 468 ms 17892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 145 ms 5324 KB Output is correct
3 Correct 144 ms 5432 KB Output is correct
4 Correct 1406 ms 33296 KB Output is correct
5 Correct 141 ms 5176 KB Output is correct
6 Correct 146 ms 5208 KB Output is correct
7 Correct 139 ms 5072 KB Output is correct
8 Correct 152 ms 5096 KB Output is correct
9 Correct 141 ms 5092 KB Output is correct
10 Correct 141 ms 5072 KB Output is correct
11 Correct 139 ms 5100 KB Output is correct
12 Correct 143 ms 5148 KB Output is correct
13 Correct 140 ms 5144 KB Output is correct
14 Correct 1409 ms 33292 KB Output is correct
15 Correct 145 ms 5176 KB Output is correct
16 Correct 1413 ms 33440 KB Output is correct
17 Correct 1414 ms 33276 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 300 KB Output is correct
2 Correct 15 ms 1360 KB Output is correct
3 Correct 15 ms 1232 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 304 KB Output is correct
14 Correct 1 ms 304 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 15 ms 1204 KB Output is correct
17 Correct 154 ms 6540 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Incorrect 0 ms 212 KB Output isn't correct
21 Halted 0 ms 0 KB -