Submission #561309

# Submission time Handle Problem Language Result Execution time Memory
561309 2022-05-12T15:39:14 Z baokhue232005 Strange Device (APIO19_strange_device) C++14
100 / 100
474 ms 20672 KB
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
// lethal option

#include<bits/stdc++.h>
using namespace std;

#define all(flg) flg.begin(), flg.end()
#define int long long
#define pb push_back
#define fi first
#define se second
#define endl "\n"
#define eb emplace_back
#define ii pair<int, int>
#define PI 3.141592653589793238462643383279502884
#define ll long long
#define for1(i, ff, gg) for(int i = ff; i <= gg; ++i)
#define for2(i, ff, gg) for(int i = ff; i >= gg; --i)
const ll mod = 1e9 + 7;
const int maxN = 1000005;
const ll oo = 2e18 + 7;
int n, a[maxN];
int x, y, z, k;
ii pr[maxN];

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
    cin >> n >> x >> y;
    x = (x / __gcd(x, y + 1));
    z = y * x;
    if(x < y) swap(x, y);
    if(oo / x <= y) z = oo;
    assert(z >= 0);
    set<ii> st;
    for1(i, 1, n){
        cin >> x >> y;
        if(y - x + 1 >= z){
            cout << z << endl;
            exit(0);
        }
        pr[i].fi = x % z;
        pr[i].se = y % z;
    }
    for1(i, 1, n){
        if(pr[i].fi > pr[i].se){
            ++n;
            pr[n].se = pr[i].se;
            pr[n].fi = 0;
            pr[i].se = z - 1;
        }
    }
    int lmx = -oo;
    sort(pr + 1, pr + n + 1);
    int ans = 0;
    for1(i, 1, n){
        lmx = max(lmx, pr[i].fi - 1);
        ans += max(0ll, pr[i].se - lmx);
        lmx = max(lmx, pr[i].se);
    }
    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 41 ms 1888 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 260 ms 15956 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 381 ms 15964 KB Output is correct
3 Correct 369 ms 15948 KB Output is correct
4 Correct 383 ms 15904 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 381 ms 15964 KB Output is correct
3 Correct 369 ms 15948 KB Output is correct
4 Correct 383 ms 15904 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 370 ms 15968 KB Output is correct
7 Correct 369 ms 15856 KB Output is correct
8 Correct 353 ms 15968 KB Output is correct
9 Correct 403 ms 15852 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 381 ms 15964 KB Output is correct
3 Correct 369 ms 15948 KB Output is correct
4 Correct 383 ms 15904 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 54 ms 1760 KB Output is correct
7 Correct 40 ms 1880 KB Output is correct
8 Correct 36 ms 1900 KB Output is correct
9 Correct 40 ms 1836 KB Output is correct
10 Correct 37 ms 1816 KB Output is correct
11 Correct 36 ms 1844 KB Output is correct
12 Correct 35 ms 1856 KB Output is correct
13 Correct 41 ms 1900 KB Output is correct
14 Correct 38 ms 1804 KB Output is correct
15 Correct 39 ms 1800 KB Output is correct
16 Correct 40 ms 1788 KB Output is correct
17 Correct 37 ms 1824 KB Output is correct
18 Correct 384 ms 15940 KB Output is correct
19 Correct 352 ms 15888 KB Output is correct
20 Correct 406 ms 15932 KB Output is correct
21 Correct 39 ms 1908 KB Output is correct
22 Correct 36 ms 1796 KB Output is correct
23 Correct 111 ms 5636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 40 ms 1788 KB Output is correct
3 Correct 38 ms 1876 KB Output is correct
4 Correct 445 ms 15860 KB Output is correct
5 Correct 38 ms 1868 KB Output is correct
6 Correct 39 ms 1812 KB Output is correct
7 Correct 38 ms 1828 KB Output is correct
8 Correct 43 ms 1780 KB Output is correct
9 Correct 40 ms 1864 KB Output is correct
10 Correct 39 ms 1868 KB Output is correct
11 Correct 38 ms 2004 KB Output is correct
12 Correct 36 ms 1868 KB Output is correct
13 Correct 39 ms 1884 KB Output is correct
14 Correct 392 ms 16012 KB Output is correct
15 Correct 38 ms 1812 KB Output is correct
16 Correct 382 ms 15940 KB Output is correct
17 Correct 359 ms 15964 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 468 KB Output is correct
3 Correct 4 ms 468 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 340 KB Output is correct
10 Correct 0 ms 340 KB Output is correct
11 Correct 0 ms 340 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 340 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 4 ms 468 KB Output is correct
17 Correct 41 ms 1888 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 340 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 340 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 260 ms 15956 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 381 ms 15964 KB Output is correct
31 Correct 369 ms 15948 KB Output is correct
32 Correct 383 ms 15904 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 370 ms 15968 KB Output is correct
35 Correct 369 ms 15856 KB Output is correct
36 Correct 353 ms 15968 KB Output is correct
37 Correct 403 ms 15852 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 54 ms 1760 KB Output is correct
40 Correct 40 ms 1880 KB Output is correct
41 Correct 36 ms 1900 KB Output is correct
42 Correct 40 ms 1836 KB Output is correct
43 Correct 37 ms 1816 KB Output is correct
44 Correct 36 ms 1844 KB Output is correct
45 Correct 35 ms 1856 KB Output is correct
46 Correct 41 ms 1900 KB Output is correct
47 Correct 38 ms 1804 KB Output is correct
48 Correct 39 ms 1800 KB Output is correct
49 Correct 40 ms 1788 KB Output is correct
50 Correct 37 ms 1824 KB Output is correct
51 Correct 384 ms 15940 KB Output is correct
52 Correct 352 ms 15888 KB Output is correct
53 Correct 406 ms 15932 KB Output is correct
54 Correct 39 ms 1908 KB Output is correct
55 Correct 36 ms 1796 KB Output is correct
56 Correct 111 ms 5636 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 40 ms 1788 KB Output is correct
59 Correct 38 ms 1876 KB Output is correct
60 Correct 445 ms 15860 KB Output is correct
61 Correct 38 ms 1868 KB Output is correct
62 Correct 39 ms 1812 KB Output is correct
63 Correct 38 ms 1828 KB Output is correct
64 Correct 43 ms 1780 KB Output is correct
65 Correct 40 ms 1864 KB Output is correct
66 Correct 39 ms 1868 KB Output is correct
67 Correct 38 ms 2004 KB Output is correct
68 Correct 36 ms 1868 KB Output is correct
69 Correct 39 ms 1884 KB Output is correct
70 Correct 392 ms 16012 KB Output is correct
71 Correct 38 ms 1812 KB Output is correct
72 Correct 382 ms 15940 KB Output is correct
73 Correct 359 ms 15964 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 336 KB Output is correct
78 Correct 0 ms 340 KB Output is correct
79 Correct 5 ms 852 KB Output is correct
80 Correct 474 ms 20672 KB Output is correct
81 Correct 451 ms 20624 KB Output is correct
82 Correct 434 ms 20520 KB Output is correct
83 Correct 413 ms 20556 KB Output is correct
84 Correct 425 ms 20444 KB Output is correct
85 Correct 418 ms 20484 KB Output is correct
86 Correct 141 ms 18140 KB Output is correct
87 Correct 0 ms 340 KB Output is correct