답안 #409655

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
409655 2021-05-21T09:41:12 Z tempus 이상한 기계 (APIO19_strange_device) C++17
5 / 100
611 ms 32568 KB
#include <bits/stdc++.h>

#define ll long long
#define endl "\n"
#define ios ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);

using namespace std;

int main() {
    ios
    int n;
    cin >> n;
    ll A, B;
    cin >> A >> B;
    ll S = 0;
    map <ll, ll> was;
    ll l[n], r[n], ans = 0;
    for (int i = 0; i < n; ++ i) {
        cin >> l[i] >> r[i];
        S += r[i] - l[i] + 1;
    }
    ll cA = A;
    cA /= __gcd(B - 1, A);

    if (B > 1e18 / cA + 1) {
        cout << S;
        return 0;
    }
    ll val = A * B / __gcd(B - 1, A);
    vector <pair <ll, ll> > v;
    for (int i = 0; i < n; ++ i) {
        if (l[i] + val <= r[i]) {
            cout << val;
            return 0;
        }
        ll ml = l[i] % val, mr = r[i] % val;
        if (ml <= mr) {
            v.push_back({ml, mr});
        }
        else {
            v.push_back({0, mr});
            v.push_back({ml, val - 1});
        }
    }
    sort(v.begin(), v.end());
    ans = v[0].second - v[0].first + 1;/*
    for (int i = 0; i < v.size(); ++ i) {
        cout << v[i].first << " " << v[i].second << endl;
    }+*/
    for (int i = 1; i < v.size(); ++ i) {
        ll nl = v[i].first, nr = v[i].second;
        if (nl > v[i - 1].second) {
            ans += nr - nl + 1;
            continue;
        }
        else if (nr <= v[i - 1].second) {
            v[i].second = v[i - 1].second;
        }
        else {
            ans += nr - v[i - 1].second;
        }
    }
    cout << ans;
    //3 3 3 4 4 7 9 17 18
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:50:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   50 |     for (int i = 1; i < v.size(); ++ i) {
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 844 KB Output is correct
3 Correct 6 ms 844 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Incorrect 1 ms 204 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 365 ms 32492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 392 ms 15948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 392 ms 15948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 392 ms 15948 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 55 ms 4024 KB Output is correct
3 Correct 52 ms 4036 KB Output is correct
4 Correct 611 ms 32568 KB Output is correct
5 Correct 53 ms 4036 KB Output is correct
6 Correct 54 ms 4020 KB Output is correct
7 Correct 51 ms 4044 KB Output is correct
8 Correct 52 ms 4036 KB Output is correct
9 Correct 50 ms 4032 KB Output is correct
10 Correct 51 ms 4024 KB Output is correct
11 Correct 52 ms 4036 KB Output is correct
12 Correct 46 ms 4036 KB Output is correct
13 Correct 50 ms 4028 KB Output is correct
14 Correct 527 ms 32448 KB Output is correct
15 Incorrect 54 ms 4168 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 6 ms 844 KB Output is correct
3 Correct 6 ms 844 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -