답안 #732790

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
732790 2023-04-29T09:56:35 Z Magikarp4000 이상한 기계 (APIO19_strange_device) C++17
0 / 100
1 ms 212 KB
#include <bits/stdc++.h>
using namespace std;
#define OPTM ios_base::sync_with_stdio(0); cin.tie(0);
#define INF int(1e9+7)
#define ln '\n' 
#define ll long long
#define ull unsigned long long
#define ui unsigned int
#define us unsigned short
#define FOR(i,s,n) for (int i = s; i < n; i++)
#define FORR(i,n,s) for (int i = n; i > s; i--)
#define FORX(u, arr) for (auto u : arr)
#define PB push_back
#define in(v,x) (v.find(x) != v.end())
#define F first
#define S second
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define UM unordered_map
#define US unordered_set
#define PQ priority_queue
#define ALL(v) v.begin(), v.end()
const ll LLINF = 1e18+1;

ll n,a,b;
vector<PLL> v;

ll gcd(ll a, ll b) {
    return (b == 0) ? a : gcd(b,a%b);
}

int main() {
    //freopen("","r",stdin);
    //freopen("","w",stdout);
    OPTM;
    cin >> n >> a >> b;
    ll p = a*b/gcd(a,b+1);
    FOR(i,0,n) {
        ll l,r; cin >> l >> r;
        ll c = l%p, d = r%p;
        if (r-l+1 >= p) return p;
        if (d >= c) v.PB({c,d});
        else {
            v.PB({c,p-1});
            v.PB({0,d});
        }
    }
    ll res = 0;
    sort(ALL(v));
    ll vn = v.size();
    ll s = v[0].F, e = v[0].S;
    FOR(i,1,vn) {
        if (v[i].F <= e) e = max(e,v[i].S);
        else {
            res += e-s+1;
            s = v[i].F;
            e = v[i].S;
        }
    }
    res += e-s+1;
    cout << res;
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 0 ms 212 KB Execution failed because the return code was nonzero
2 Halted 0 ms 0 KB -