답안 #729713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729713 2023-04-24T11:42:41 Z danikoynov 이상한 기계 (APIO19_strange_device) C++14
5 / 100
1390 ms 48952 KB
#include<bits/stdc++.h>
#define endl '\n'

using namespace std;
typedef long long ll;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

const int maxn = 1e6 + 10;

int n;
ll l[maxn], r[maxn];
ll A, B;

struct point
{
    ll x, t;
    point(ll _x = 0, ll _t = 0)
    {
        x = _x;
        t = _t;
    }

    bool operator < (const point &p) const
    {
        if (x == p.x)
            return t > p.t;
        return x < p.x;
    }
};


vector < point > vec;
void add_segment(int l, int r)
{
    vec.push_back(point(l, 1));
    vec.push_back(point(r, -1));
}
void solve()
{
    cin >> n >> A >> B;

    for (int i = 1; i <= n; i ++)
    {
        cin >> l[i] >> r[i];
    }
    ll period = 1e18 + 10;
        ll g = __gcd(A, B + 1);
    if ((double)(A) * (double)(B) / (double)(g) < (double)period)
        period = A * B / g;


    for (int i = 1; i <= n; i ++)
    {


            if (r[i] - l[i] + 1 >= period)
            {
                cout << period << endl;
                return;
            }

            ll x = l[i] % period, y = r[i] % period;
            if (x <= y)
            {
                add_segment(x, y);
            }
            else
            {
                add_segment(0, y);
                add_segment(x, period);
            }

    }

    sort(vec.begin(), vec.end());
    ll ans = 0, cnt = 0;
    ll st = -1;
    for (int i = 0; i < vec.size(); i ++)
    {
        ///cout << vec[i].x << " " << vec[i].t << endl;
        if (vec[i].t == 1)
        {
            if (cnt)
                cnt ++;
            else
            {
                st = vec[i].x;
                cnt = 1;
            }
        }
        else
        {
            if (cnt > 1)
                cnt --;
            else
            {
                ans = ans + vec[i].x - st + 1;
                cnt = 0;
            }
        }

    }
    cout << ans << endl;
}


int main()
{
    solve();
    return 0;
}
/**
1  10000 3312452154131231
1 1
*/

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:84:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<point>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for (int i = 0; i < vec.size(); i ++)
      |                     ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 15 ms 1012 KB Output is correct
3 Incorrect 17 ms 1104 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 280 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 2 ms 340 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1390 ms 48836 KB Output is correct
3 Incorrect 1316 ms 48952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1390 ms 48836 KB Output is correct
3 Incorrect 1316 ms 48952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1390 ms 48836 KB Output is correct
3 Incorrect 1316 ms 48952 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 143 ms 6068 KB Output is correct
3 Incorrect 142 ms 6120 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 224 KB Output is correct
2 Correct 15 ms 1012 KB Output is correct
3 Incorrect 17 ms 1104 KB Output isn't correct
4 Halted 0 ms 0 KB -