답안 #729715

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729715 2023-04-24T11:43:58 Z danikoynov 이상한 기계 (APIO19_strange_device) C++14
5 / 100
1616 ms 49784 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(ll l, ll 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 212 KB Output is correct
2 Correct 15 ms 1100 KB Output is correct
3 Incorrect 15 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 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
2 Correct 1434 ms 48936 KB Output is correct
3 Incorrect 1470 ms 48888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1434 ms 48936 KB Output is correct
3 Incorrect 1470 ms 48888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1434 ms 48936 KB Output is correct
3 Incorrect 1470 ms 48888 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 150 ms 6000 KB Output is correct
3 Correct 145 ms 6092 KB Output is correct
4 Correct 1616 ms 49784 KB Output is correct
5 Correct 157 ms 9840 KB Output is correct
6 Correct 150 ms 9820 KB Output is correct
7 Correct 146 ms 9884 KB Output is correct
8 Correct 144 ms 9784 KB Output is correct
9 Correct 154 ms 9848 KB Output is correct
10 Correct 159 ms 9884 KB Output is correct
11 Correct 141 ms 9792 KB Output is correct
12 Incorrect 141 ms 9788 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 15 ms 1100 KB Output is correct
3 Incorrect 15 ms 1104 KB Output isn't correct
4 Halted 0 ms 0 KB -