답안 #1003748

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1003748 2024-06-20T16:46:02 Z underwaterkillerwhale 이상한 기계 (APIO19_strange_device) C++17
100 / 100
323 ms 53292 KB
//#ifdef ONLINE_JUDGE
//    #include "cyberland.h"
//#endif

#include <bits/stdc++.h>
#define se              second
#define fs              first
#define mp              make_pair
#define pb              push_back
#define ll              long long
#define ii              pair<ll,ll>
#define ld              long double
#define SZ(v)           (int)v.size()
#define ALL(v)          v.begin(), v.end()
#define bit(msk, i)     ((msk >> i) & 1)
#define iter(id, v)     for(auto id : v)
#define rep(i,m,n)      for(int i=(m); i<=(n); i++)
#define reb(i,m,n)      for(int i=(m); i>=(n); i--)

using namespace std;

mt19937_64 rd(chrono :: steady_clock :: now().time_since_epoch().count());
ll Rand(ll l, ll r) { return uniform_int_distribution<ll> (l, r)(rd); }

const int N  = 1e6 + 7;
const int Mod = 1e9 +7;
const int szBL = 50;
const ll INF = 2e18 + 7;
const int BASE = 137;

int n;
ll A, B;
pair<ll, ll> a[N];


void solution() {
    cin >> n >> A >> B;
    rep (i ,1, n) {
        cin >> a[i].fs >> a[i].se;
    }
    ll K = min((__int128)INF, (__int128)A / __gcd(A, B + 1) * B);
    rep (i, 1, n) if (a[i].se - a[i].fs + 1>= K) {
        cout << K <<"\n";
        return;
    }
    int prevn = n;
    rep (i, 1, n) {
        a[i].se %= K;
        a[i].fs %= K;
        if (a[i].se < a[i].fs) {
            a[++n] = mp(0, a[i].se);
            a[i].se = K - 1;
        }
    }
    sort (a + 1 , a + 1 + n);
    ll mnL = a[1].fs, mxR = a[1].se;
    ll res = 0;
    rep (i, 2, n) {
        if (a[i].fs > mxR) {
            res += mxR - mnL + 1;
            mnL = a[i].fs;
            mxR = a[i].se;
        }
        else {
            mxR = max(mxR, a[i].se);
        }
    }
    res += mxR - mnL + 1;
    cout << res <<"\n";

}

#define file(name) freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout);
int main () {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//    file ("c");
    int num_Test = 1;
//    cin >> num_Test;
    while (num_Test--)
        solution();
}

/*
7
1 2 3 1 2 1 3
1
4 4 30
3
1 1 2 1
0 1 5
0 2 5
1 3 2
2 3 4


3 2
0 1 5
0 2 5
1
1 2

*/

Compilation message

strange_device.cpp: In function 'void solution()':
strange_device.cpp:46:9: warning: unused variable 'prevn' [-Wunused-variable]
   46 |     int prevn = n;
      |         ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 28 ms 1988 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 178 ms 15856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 250 ms 15916 KB Output is correct
3 Correct 246 ms 15956 KB Output is correct
4 Correct 259 ms 15956 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 250 ms 15916 KB Output is correct
3 Correct 246 ms 15956 KB Output is correct
4 Correct 259 ms 15956 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 251 ms 16092 KB Output is correct
7 Correct 251 ms 15956 KB Output is correct
8 Correct 246 ms 15956 KB Output is correct
9 Correct 270 ms 15880 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 250 ms 15916 KB Output is correct
3 Correct 246 ms 15956 KB Output is correct
4 Correct 259 ms 15956 KB Output is correct
5 Correct 0 ms 344 KB Output is correct
6 Correct 27 ms 2032 KB Output is correct
7 Correct 27 ms 1884 KB Output is correct
8 Correct 24 ms 1884 KB Output is correct
9 Correct 25 ms 1872 KB Output is correct
10 Correct 25 ms 1880 KB Output is correct
11 Correct 26 ms 1884 KB Output is correct
12 Correct 25 ms 1988 KB Output is correct
13 Correct 27 ms 1936 KB Output is correct
14 Correct 26 ms 1764 KB Output is correct
15 Correct 27 ms 1872 KB Output is correct
16 Correct 27 ms 1880 KB Output is correct
17 Correct 28 ms 1844 KB Output is correct
18 Correct 253 ms 16092 KB Output is correct
19 Correct 266 ms 15956 KB Output is correct
20 Correct 290 ms 15944 KB Output is correct
21 Correct 28 ms 1880 KB Output is correct
22 Correct 25 ms 1884 KB Output is correct
23 Correct 75 ms 5752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 28 ms 2008 KB Output is correct
3 Correct 30 ms 1876 KB Output is correct
4 Correct 306 ms 16028 KB Output is correct
5 Correct 28 ms 1880 KB Output is correct
6 Correct 28 ms 1944 KB Output is correct
7 Correct 28 ms 1936 KB Output is correct
8 Correct 28 ms 1884 KB Output is correct
9 Correct 27 ms 1880 KB Output is correct
10 Correct 28 ms 1956 KB Output is correct
11 Correct 28 ms 1884 KB Output is correct
12 Correct 24 ms 1884 KB Output is correct
13 Correct 25 ms 1880 KB Output is correct
14 Correct 275 ms 15956 KB Output is correct
15 Correct 27 ms 1988 KB Output is correct
16 Correct 289 ms 15884 KB Output is correct
17 Correct 272 ms 16080 KB Output is correct
18 Correct 0 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 4 ms 604 KB Output is correct
3 Correct 4 ms 604 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 3 ms 604 KB Output is correct
17 Correct 28 ms 1988 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 344 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 178 ms 15856 KB Output is correct
29 Correct 0 ms 348 KB Output is correct
30 Correct 250 ms 15916 KB Output is correct
31 Correct 246 ms 15956 KB Output is correct
32 Correct 259 ms 15956 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 251 ms 16092 KB Output is correct
35 Correct 251 ms 15956 KB Output is correct
36 Correct 246 ms 15956 KB Output is correct
37 Correct 270 ms 15880 KB Output is correct
38 Correct 0 ms 344 KB Output is correct
39 Correct 27 ms 2032 KB Output is correct
40 Correct 27 ms 1884 KB Output is correct
41 Correct 24 ms 1884 KB Output is correct
42 Correct 25 ms 1872 KB Output is correct
43 Correct 25 ms 1880 KB Output is correct
44 Correct 26 ms 1884 KB Output is correct
45 Correct 25 ms 1988 KB Output is correct
46 Correct 27 ms 1936 KB Output is correct
47 Correct 26 ms 1764 KB Output is correct
48 Correct 27 ms 1872 KB Output is correct
49 Correct 27 ms 1880 KB Output is correct
50 Correct 28 ms 1844 KB Output is correct
51 Correct 253 ms 16092 KB Output is correct
52 Correct 266 ms 15956 KB Output is correct
53 Correct 290 ms 15944 KB Output is correct
54 Correct 28 ms 1880 KB Output is correct
55 Correct 25 ms 1884 KB Output is correct
56 Correct 75 ms 5752 KB Output is correct
57 Correct 0 ms 344 KB Output is correct
58 Correct 28 ms 2008 KB Output is correct
59 Correct 30 ms 1876 KB Output is correct
60 Correct 306 ms 16028 KB Output is correct
61 Correct 28 ms 1880 KB Output is correct
62 Correct 28 ms 1944 KB Output is correct
63 Correct 28 ms 1936 KB Output is correct
64 Correct 28 ms 1884 KB Output is correct
65 Correct 27 ms 1880 KB Output is correct
66 Correct 28 ms 1956 KB Output is correct
67 Correct 28 ms 1884 KB Output is correct
68 Correct 24 ms 1884 KB Output is correct
69 Correct 25 ms 1880 KB Output is correct
70 Correct 275 ms 15956 KB Output is correct
71 Correct 27 ms 1988 KB Output is correct
72 Correct 289 ms 15884 KB Output is correct
73 Correct 272 ms 16080 KB Output is correct
74 Correct 0 ms 344 KB Output is correct
75 Correct 0 ms 460 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 348 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 3 ms 860 KB Output is correct
80 Correct 311 ms 53292 KB Output is correct
81 Correct 319 ms 53136 KB Output is correct
82 Correct 323 ms 53248 KB Output is correct
83 Correct 313 ms 53052 KB Output is correct
84 Correct 303 ms 53112 KB Output is correct
85 Correct 314 ms 53212 KB Output is correct
86 Correct 78 ms 18260 KB Output is correct
87 Correct 0 ms 348 KB Output is correct