답안 #264079

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
264079 2020-08-14T05:00:59 Z batmendbar 이상한 기계 (APIO19_strange_device) C++14
10 / 100
573 ms 20976 KB
#include <bits/stdc++.h>
using namespace std;

const long long N = ((long long)1e18) + 5;

long long gcd(long long x, long long y)
{
    if (x < y)
        swap(x, y);
    while (y)
    {
        x %= y;
        swap(x, y);
    }
    return x;
}

vector<pair<long long, long long>> v;

long long ans;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    long long n, a, b;
    cin >> n >> a >> b;
    long long aa = a / gcd(a, b + 1);
    long long len;
    if (aa > (N / b))
        len = N;
    else
        len = a * b;
    for (long long i = 0; i < n; i++)
    {
        long long bg, en;
        cin >> bg >> en;
        if (en - bg >= len)
        {
            cout << len << '\n';
            exit(0);
        }
        bg %= len;
        en %= len;
        if (bg > en)
        {
            v.push_back(make_pair(bg, len - 1));
            v.push_back(make_pair(0, en));
        }
        else
        {
            v.push_back(make_pair(bg, en));
        }
    }
    sort(v.begin(), v.end());
    long long bg = 0, en = -1;
    for (pair<long long, long long> x : v)
    {
        long long bgg = x.first;
        long long enn = x.second;
        if (bgg > en)
        {
            ans += en - bg + 1;
            bg = bgg;
            en = enn;
            continue;
        }
        if (bgg <= en)
        {
            en = max(en, enn);
        }
    }
    ans += en - bg + 1;
    cout << ans << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 9 ms 768 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 360 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 426 ms 16944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 489 ms 16852 KB Output is correct
3 Incorrect 573 ms 16844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 489 ms 16852 KB Output is correct
3 Incorrect 573 ms 16844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 489 ms 16852 KB Output is correct
3 Incorrect 573 ms 16844 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 59 ms 2548 KB Output is correct
3 Correct 67 ms 2544 KB Output is correct
4 Correct 570 ms 20976 KB Output is correct
5 Correct 49 ms 5732 KB Output is correct
6 Correct 48 ms 5740 KB Output is correct
7 Correct 50 ms 5740 KB Output is correct
8 Correct 49 ms 5744 KB Output is correct
9 Correct 50 ms 5740 KB Output is correct
10 Correct 63 ms 5740 KB Output is correct
11 Correct 49 ms 5740 KB Output is correct
12 Correct 50 ms 5736 KB Output is correct
13 Correct 62 ms 5772 KB Output is correct
14 Correct 545 ms 20948 KB Output is correct
15 Incorrect 50 ms 5736 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 5 ms 768 KB Output is correct
3 Correct 9 ms 768 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -