Submission #782609

# Submission time Handle Problem Language Result Execution time Memory
782609 2023-07-14T06:28:00 Z makanhulia Strange Device (APIO19_strange_device) C++17
65 / 100
367 ms 16924 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 / (__int128_t)__gcd(a, b+1);
    vector<pii> v;
    bool ok=1;
    int ya;
    for(int i=1; i<=n; i++) {
        int l, r;
        cin >> l >> r;
        if((r-l+1) >= cycle) {
            ya=r-l+1;
            ok=0;
        }
        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;
        }
    }
    if(!ok) {
        cout << ya << endl;
        return;
    }
    ans+=(r-l+1);
    cout << ans << endl;
}
 
signed main() {
    jess;
    solve();
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 34 ms 2468 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 Incorrect 0 ms 256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 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 216 ms 16808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 318 ms 16816 KB Output is correct
3 Correct 331 ms 16924 KB Output is correct
4 Correct 297 ms 16860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 318 ms 16816 KB Output is correct
3 Correct 331 ms 16924 KB Output is correct
4 Correct 297 ms 16860 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 314 ms 16840 KB Output is correct
7 Correct 307 ms 16864 KB Output is correct
8 Correct 305 ms 16852 KB Output is correct
9 Correct 364 ms 16756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 318 ms 16816 KB Output is correct
3 Correct 331 ms 16924 KB Output is correct
4 Correct 297 ms 16860 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 30 ms 2508 KB Output is correct
7 Correct 31 ms 2376 KB Output is correct
8 Correct 29 ms 2500 KB Output is correct
9 Correct 30 ms 2480 KB Output is correct
10 Correct 28 ms 2512 KB Output is correct
11 Correct 30 ms 2512 KB Output is correct
12 Correct 29 ms 2512 KB Output is correct
13 Correct 32 ms 2440 KB Output is correct
14 Correct 33 ms 2452 KB Output is correct
15 Correct 32 ms 2412 KB Output is correct
16 Correct 34 ms 2504 KB Output is correct
17 Correct 30 ms 2464 KB Output is correct
18 Correct 316 ms 16776 KB Output is correct
19 Correct 308 ms 16776 KB Output is correct
20 Correct 345 ms 16744 KB Output is correct
21 Correct 32 ms 2540 KB Output is correct
22 Correct 28 ms 2512 KB Output is correct
23 Correct 90 ms 8636 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 31 ms 2484 KB Output is correct
3 Correct 36 ms 2464 KB Output is correct
4 Correct 367 ms 16776 KB Output is correct
5 Correct 33 ms 2512 KB Output is correct
6 Correct 33 ms 2464 KB Output is correct
7 Correct 32 ms 2508 KB Output is correct
8 Correct 32 ms 2452 KB Output is correct
9 Correct 33 ms 2512 KB Output is correct
10 Correct 31 ms 2496 KB Output is correct
11 Correct 34 ms 2428 KB Output is correct
12 Correct 30 ms 2512 KB Output is correct
13 Correct 32 ms 2468 KB Output is correct
14 Correct 347 ms 16804 KB Output is correct
15 Correct 36 ms 2524 KB Output is correct
16 Correct 305 ms 16864 KB Output is correct
17 Correct 302 ms 16744 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 34 ms 2468 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Incorrect 0 ms 256 KB Output isn't correct
21 Halted 0 ms 0 KB -