답안 #783498

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
783498 2023-07-15T01:49:06 Z makanhulia 이상한 기계 (APIO19_strange_device) C++17
100 / 100
368 ms 19088 KB
# include <bits/stdc++.h>
# define int long long
# define vi vector<int>
# define pb push_back
# define pii pair<int, int>
# define fi first
# define se second
# define endl '\n'
# define jess ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

using namespace std;

int n, a, b;

void solve() {
    cin >> n >> a >> b;
    __int128_t t=(__int128_t)a*b;
    __int128_t cycle=t / __gcd(a, b+1);
    vector<pii> v;
    bool ok=1;
    int ya;
    if(cycle <= 1e18) {
        int tm=a*b;
        for(int i=1; i<=n; i++) {
            int l, r;
            cin >> l >> r;
            if((r-l+1) >= tm) {
                cout << min(r-l+1, tm) << endl;
                return;
            }
            l%=cycle;
            r%=cycle;
            if(r < l) {
                v.pb({l, cycle-1});
                v.pb({0, r});
            } else {
                v.pb({l, r});
            }
        }
    } else {
        for(int i=1; i<=n; i++) {
            int l, r;
            cin >> l >> r;
            if((r-l+1) >= cycle) {
                cout << r-l+1 << endl;
                return;
            }
            l%=cycle;
            r%=cycle;
            if(r < l) {
                v.pb({l, cycle-1});
                v.pb({0, r});
            } else {
                v.pb({l, r});
            }
        }
    }
    sort(v.begin(), v.end());
    bool st=1;
    int l=0, r=1, ans=0;
    // for(pii i : v) cout << "l r " << i.fi << " " << i.se << endl;
    for(auto i : v) {
        if(st) {
            l=i.fi, r=i.se;
            st=0;
            continue;
        }
        if(i.fi>=l && i.fi<=r) {
            r=max(r, i.se);
        } else {
            ans+=(r-l+1);
            l=i.fi, r=i.se;
        }
    }
    ans+=(r-l+1);
    cout << ans << endl;
}
 
signed main() {
    jess;
    solve();
}

Compilation message

strange_device.cpp: In function 'void solve()':
strange_device.cpp:20:10: warning: unused variable 'ok' [-Wunused-variable]
   20 |     bool ok=1;
      |          ^~
strange_device.cpp:21:9: warning: unused variable 'ya' [-Wunused-variable]
   21 |     int ya;
      |         ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 984 KB Output is correct
3 Correct 4 ms 1056 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 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 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 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 1052 KB Output is correct
17 Correct 38 ms 4132 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 320 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 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 372 KB Output is correct
5 Correct 226 ms 17396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 330 ms 17360 KB Output is correct
3 Correct 311 ms 18004 KB Output is correct
4 Correct 318 ms 19032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 330 ms 17360 KB Output is correct
3 Correct 311 ms 18004 KB Output is correct
4 Correct 318 ms 19032 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 324 ms 19052 KB Output is correct
7 Correct 319 ms 19052 KB Output is correct
8 Correct 324 ms 19028 KB Output is correct
9 Correct 347 ms 19032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 330 ms 17360 KB Output is correct
3 Correct 311 ms 18004 KB Output is correct
4 Correct 318 ms 19032 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 30 ms 4156 KB Output is correct
7 Correct 34 ms 4452 KB Output is correct
8 Correct 32 ms 4164 KB Output is correct
9 Correct 40 ms 4284 KB Output is correct
10 Correct 31 ms 4208 KB Output is correct
11 Correct 34 ms 4316 KB Output is correct
12 Correct 32 ms 4456 KB Output is correct
13 Correct 34 ms 4132 KB Output is correct
14 Correct 34 ms 4288 KB Output is correct
15 Correct 35 ms 4336 KB Output is correct
16 Correct 34 ms 4116 KB Output is correct
17 Correct 32 ms 4552 KB Output is correct
18 Correct 321 ms 18792 KB Output is correct
19 Correct 306 ms 18744 KB Output is correct
20 Correct 332 ms 18980 KB Output is correct
21 Correct 40 ms 4228 KB Output is correct
22 Correct 31 ms 4188 KB Output is correct
23 Correct 96 ms 10816 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 38 ms 3896 KB Output is correct
3 Correct 33 ms 3800 KB Output is correct
4 Correct 355 ms 18028 KB Output is correct
5 Correct 33 ms 3664 KB Output is correct
6 Correct 32 ms 3664 KB Output is correct
7 Correct 32 ms 3600 KB Output is correct
8 Correct 33 ms 3568 KB Output is correct
9 Correct 32 ms 3564 KB Output is correct
10 Correct 32 ms 3620 KB Output is correct
11 Correct 35 ms 3620 KB Output is correct
12 Correct 29 ms 3592 KB Output is correct
13 Correct 32 ms 3584 KB Output is correct
14 Correct 331 ms 18032 KB Output is correct
15 Correct 32 ms 3528 KB Output is correct
16 Correct 320 ms 18448 KB Output is correct
17 Correct 323 ms 19004 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 984 KB Output is correct
3 Correct 4 ms 1056 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 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 320 KB Output is correct
11 Correct 1 ms 212 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 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 4 ms 1052 KB Output is correct
17 Correct 38 ms 4132 KB Output is correct
18 Correct 1 ms 320 KB Output is correct
19 Correct 1 ms 320 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 324 KB Output is correct
24 Correct 1 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 372 KB Output is correct
28 Correct 226 ms 17396 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 330 ms 17360 KB Output is correct
31 Correct 311 ms 18004 KB Output is correct
32 Correct 318 ms 19032 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 324 ms 19052 KB Output is correct
35 Correct 319 ms 19052 KB Output is correct
36 Correct 324 ms 19028 KB Output is correct
37 Correct 347 ms 19032 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 30 ms 4156 KB Output is correct
40 Correct 34 ms 4452 KB Output is correct
41 Correct 32 ms 4164 KB Output is correct
42 Correct 40 ms 4284 KB Output is correct
43 Correct 31 ms 4208 KB Output is correct
44 Correct 34 ms 4316 KB Output is correct
45 Correct 32 ms 4456 KB Output is correct
46 Correct 34 ms 4132 KB Output is correct
47 Correct 34 ms 4288 KB Output is correct
48 Correct 35 ms 4336 KB Output is correct
49 Correct 34 ms 4116 KB Output is correct
50 Correct 32 ms 4552 KB Output is correct
51 Correct 321 ms 18792 KB Output is correct
52 Correct 306 ms 18744 KB Output is correct
53 Correct 332 ms 18980 KB Output is correct
54 Correct 40 ms 4228 KB Output is correct
55 Correct 31 ms 4188 KB Output is correct
56 Correct 96 ms 10816 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 38 ms 3896 KB Output is correct
59 Correct 33 ms 3800 KB Output is correct
60 Correct 355 ms 18028 KB Output is correct
61 Correct 33 ms 3664 KB Output is correct
62 Correct 32 ms 3664 KB Output is correct
63 Correct 32 ms 3600 KB Output is correct
64 Correct 33 ms 3568 KB Output is correct
65 Correct 32 ms 3564 KB Output is correct
66 Correct 32 ms 3620 KB Output is correct
67 Correct 35 ms 3620 KB Output is correct
68 Correct 29 ms 3592 KB Output is correct
69 Correct 32 ms 3584 KB Output is correct
70 Correct 331 ms 18032 KB Output is correct
71 Correct 32 ms 3528 KB Output is correct
72 Correct 320 ms 18448 KB Output is correct
73 Correct 323 ms 19004 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 0 ms 212 KB Output is correct
76 Correct 0 ms 212 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 4 ms 984 KB Output is correct
80 Correct 364 ms 18940 KB Output is correct
81 Correct 368 ms 18368 KB Output is correct
82 Correct 335 ms 18504 KB Output is correct
83 Correct 354 ms 18504 KB Output is correct
84 Correct 347 ms 19088 KB Output is correct
85 Correct 336 ms 18988 KB Output is correct
86 Correct 97 ms 10844 KB Output is correct
87 Correct 0 ms 212 KB Output is correct