답안 #531651

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
531651 2022-03-01T07:59:55 Z 79brue 이상한 기계 (APIO19_strange_device) C++14
10 / 100
485 ms 32424 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
ll a, b;
ll l[1000002], r[1000002];

int main(){
    scanf("%d %lld %lld", &n, &a, &b);
    for(int i=1; i<=n; i++) scanf("%lld %lld", &l[i], &r[i]);

    if(1000000000000000000LL / a + 1 <= b){
        ll ans = 0;
        for(int i=1; i<=n; i++) ans += r[i] - l[i] + 1;
        printf("%lld", ans);
        return 0;
    }

    if(b%a==1) a=b;
    else a = a*b;
    for(int i=1; i<=n; i++){
        if(r[i] - l[i] >= a-1){
            printf("%lld", a);
            return 0;
        }
    }

    vector<pair<ll, ll> > vec;
    for(int i=1; i<=n; i++){
        if(l[i]%a <= r[i]%a) vec.push_back(make_pair(l[i]%a, r[i]%a));
        else{
            vec.push_back(make_pair(0, r[i]%a));
            vec.push_back(make_pair(l[i]%a, a-1));
        }
    }
    sort(vec.begin(), vec.end());

    ll ans = 0;
    ll rMax = vec[0].second;
    ll lPnt = vec[0].first;
    for(int i=0; i<(int)vec.size(); i++){
        rMax = max(rMax, vec[i].second);
        if(i<(int)vec.size()-1 && rMax < vec[i+1].first){
            ans += rMax - lPnt + 1;
            lPnt = vec[i+1].first;
        }
        else if(i==(int)vec.size()-1){
            ans += rMax - lPnt + 1;
        }
        else{
            rMax = max(rMax, vec[i].second);
        }
    }
    printf("%lld", ans);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:12:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |     scanf("%d %lld %lld", &n, &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:13:34: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     for(int i=1; i<=n; i++) scanf("%lld %lld", &l[i], &r[i]);
      |                             ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 5 ms 812 KB Output is correct
3 Correct 5 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 0 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 208 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 319 ms 32380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 383 ms 15916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 383 ms 15916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 383 ms 15916 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 44 ms 4024 KB Output is correct
3 Correct 49 ms 4020 KB Output is correct
4 Correct 485 ms 32424 KB Output is correct
5 Correct 44 ms 4000 KB Output is correct
6 Correct 44 ms 4024 KB Output is correct
7 Correct 44 ms 4044 KB Output is correct
8 Correct 46 ms 3960 KB Output is correct
9 Correct 46 ms 4024 KB Output is correct
10 Correct 50 ms 3964 KB Output is correct
11 Correct 45 ms 3992 KB Output is correct
12 Correct 42 ms 4016 KB Output is correct
13 Correct 45 ms 3976 KB Output is correct
14 Correct 471 ms 32404 KB Output is correct
15 Incorrect 48 ms 4032 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 5 ms 812 KB Output is correct
3 Correct 5 ms 844 KB Output is correct
4 Incorrect 1 ms 204 KB Output isn't correct
5 Halted 0 ms 0 KB -