답안 #721612

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721612 2023-04-11T05:35:52 Z GrandTiger1729 이상한 기계 (APIO19_strange_device) C++17
0 / 100
1 ms 468 KB
#include <bits/stdc++.h>
using namespace std;

const long long INF = 1e18 + 10;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n; cin >> n;
    long long A, B; cin >> A >> B;
    if ((__int128_t)1 * A * B / __gcd(A, B + 1) >= INF){
        long long ans = 0;
        for (int i = 0; i < n; i++){
            long long l, r; cin >> l >> r;
            ans += r - l + 1;
        }
        cout << ans << '\n';
        return 0;
    }
    long long D = (__int128_t)1 * A * B / __gcd(A, B + 1);
    assert(n == 1);
    vector<pair<long long, long long>> res;
    for (int i = 0; i < n; i++){
        long long l, r; cin >> l >> r;
        r++;
        if (r - l >= D){
            cout << D << '\n';
            return 0;
        }
        long long ll = D * (l / D + bool(l % D)), rr = D * (r / D);
        // cerr << l << ' ' << r << ' ' << ll << ' ' << rr << endl;
        if (ll > rr){
            res.emplace_back(l, r);
        }else{
            res.emplace_back(l % D, D);
            res.emplace_back(0, r % D);
        }
    }
    // for (auto &[l, r]: res)
    //     cerr << l << ' ' << r << endl;
    assert(false);
    long long ans = 0;
    for (auto &[l, r]: res)
        ans += r - l;
    cout << ans << '\n';
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 428 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Runtime error 1 ms 468 KB Execution killed with signal 6
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Runtime error 1 ms 468 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Runtime error 1 ms 428 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -