제출 #392246

#제출 시각아이디문제언어결과실행 시간메모리
392246BartolM이상한 기계 (APIO19_strange_device)C++17
100 / 100
605 ms53508 KiB
#define DEBUG 1
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const ll MAX=1e18+2;

int n, fl=0;
ll A, B, gc;
vector <pll> v;

int main() {
    scanf("%d %lld %lld", &n, &A, &B);
    gc=__gcd(A, B+1);
    ll block=A/gc*B;
    if (A/gc>MAX/B) block=MAX;

    for (int i=0; i<n; ++i) {
        ll l, r;
        scanf("%lld %lld", &l, &r);
        if (r-l+1>block) fl=1;
        l%=block; r%=block;

        if (l<=r) v.pb(mp(l, r));
        else v.pb(mp(l, block-1)), v.pb(mp(0, r));
    }
    if (fl) {
        printf("%lld\n", block);
        return 0;
    }
    sort(v.begin(), v.end());
    ll lef=-1, rig=-2, sol=0;
    for (pll pp:v) {
        if (rig<pp.X) sol+=rig-lef+1, rig=pp.Y, lef=pp.X;
        else rig=max(rig, pp.Y);
    }
    sol+=rig-lef+1;
    printf("%lld\n", sol);
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

strange_device.cpp: In function 'int main()':
strange_device.cpp:24:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   24 |     scanf("%d %lld %lld", &n, &A, &B);
      |     ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:31:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   31 |         scanf("%lld %lld", &l, &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...