제출 #1358042

#제출 시각아이디문제언어결과실행 시간메모리
1358042eliminator_101이상한 기계 (APIO19_strange_device)C++20
100 / 100
269 ms32588 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n,a,b;
    cin>>n>>a>>b;
    vector<pair<int,int>>v(n);
    for(auto&[c,d]:v){
        cin>>c>>d;
    }
    int g = __gcd(a,b+1);
    g = a/g; // number of cycles required to get back the same x
    __int128 tt= g;
    tt*=b;
    int mx = -1,ans=0;
    vector<pair<int,int>>v1;
    if(tt<=(__int128)1e18){
        for (auto[c,d]:v){
            if(d-c>tt){
                ans=tt;
                break;
            }
            int c1 = c%((int)tt);
            int d1 = d%((int)tt);
            if(c1>d1){
                v1.push_back({c1,tt-1});
                v1.push_back({0LL,d1});
            }else{
                v1.push_back({c1,d1});
            }
        }
    }else{
        for(auto[c,d]:v){
            v1.push_back({c,d});
        }
    }
    if(ans){
        cout<<ans<<endl;
        return 0;
    }
    sort(v1.begin(), v1.end());
    for (auto[c,d]:v1){
        if (c>mx){
            ans+=d-c+1;
            mx=d;
        }else if(d>mx){ 
            ans+=d-mx;
            mx=d;
        }
    }
    cout<<ans<<endl;
    return 0;
}
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…
#결과 실행 시간메모리채점기 출력
결과를 불러오는 중입니다…