Submission #720912

#TimeUsernameProblemLanguageResultExecution timeMemory
720912Username4132이상한 기계 (APIO19_strange_device)C++14
100 / 100
492 ms53168 KiB
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;
#define forn(i, n) for(int i=0; i<(int)n; ++i)
#define F first
#define S second

const int MAXN=1000010;
const ll MX = 1000000000000001000;
int n, cnt=0;
ll a, b, D;
pll arr[2*MAXN];

int main(){
    scanf("%d %lld %lld", &n, &a, &b);
    ll part = a/__gcd(a, b+1);
    D=((b > (MX/part))? MX : part*b);

    forn(i, n){
        ll l, r;
        scanf("%lld %lld", &l, &r); ++r;
        if(r-l>=D){
            printf("%lld\n", D);
            return 0;
        }
        ll L=(l%D), R=(r%D);
        if(L<R) arr[cnt++]={L, R};
        else arr[cnt++]={L, D}, arr[cnt++]={0, R};
    }

    arr[cnt++]={MX, MX};
    sort(arr, arr+cnt);
    ll st=-MX, en = -MX, sum=0;
    forn(i, cnt){
        if(en<=arr[i].F){
            sum+=(en-st);
            st=arr[i].F;
        }
        en = max(en, arr[i].S);
    }
    printf("%lld\n", sum);
}

Compilation message (stderr)

strange_device.cpp: In function 'int main()':
strange_device.cpp:17:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |     scanf("%d %lld %lld", &n, &a, &b);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:23:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         scanf("%lld %lld", &l, &r); ++r;
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...