답안 #729711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729711 2023-04-24T11:37:24 Z danikoynov 이상한 기계 (APIO19_strange_device) C++14
20 / 100
1275 ms 32628 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 < pair < ll, ll > > vec;
void add_segment(int l, int r)
{
    vec.push_back({l, r});
}
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;
            }

            r[i] ++;
            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 to = -1;
    for (int i = 0; i < vec.size(); i ++)
    {
        to = max(to, vec[i].first);
        ans = ans + max((ll)(0), vec[i].second - to);
        to = max(to, vec[i].second);
    }
    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<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   84 |     for (int i = 0; i < vec.size(); i ++)
      |                     ~~^~~~~~~~~~~~
strange_device.cpp:82:17: warning: unused variable 'cnt' [-Wunused-variable]
   82 |     ll ans = 0, cnt = 0;
      |                 ^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 14 ms 920 KB Output is correct
3 Correct 16 ms 968 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 14 ms 1032 KB Output is correct
17 Correct 146 ms 4660 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 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 Correct 2 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 2 ms 340 KB Output is correct
5 Correct 930 ms 32548 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1275 ms 32576 KB Output is correct
3 Incorrect 1257 ms 32628 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1275 ms 32576 KB Output is correct
3 Incorrect 1257 ms 32628 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1275 ms 32576 KB Output is correct
3 Incorrect 1257 ms 32628 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 316 KB Output is correct
2 Correct 144 ms 4612 KB Output is correct
3 Incorrect 137 ms 4220 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 14 ms 920 KB Output is correct
3 Correct 16 ms 968 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 312 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 312 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 14 ms 1032 KB Output is correct
17 Correct 146 ms 4660 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 930 ms 32548 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1275 ms 32576 KB Output is correct
31 Incorrect 1257 ms 32628 KB Output isn't correct
32 Halted 0 ms 0 KB -