Submission #782615

# Submission time Handle Problem Language Result Execution time Memory
782615 2023-07-14T06:30:46 Z andecaandeci Strange Device (APIO19_strange_device) C++17
65 / 100
367 ms 16856 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;
    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 0 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 0 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 0 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 33 ms 2496 KB Output is correct
18 Correct 1 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 212 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 206 ms 16832 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 313 ms 16768 KB Output is correct
3 Correct 333 ms 16812 KB Output is correct
4 Correct 290 ms 16820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 313 ms 16768 KB Output is correct
3 Correct 333 ms 16812 KB Output is correct
4 Correct 290 ms 16820 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 297 ms 16748 KB Output is correct
7 Correct 301 ms 16808 KB Output is correct
8 Correct 354 ms 16836 KB Output is correct
9 Correct 320 ms 16856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 313 ms 16768 KB Output is correct
3 Correct 333 ms 16812 KB Output is correct
4 Correct 290 ms 16820 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 35 ms 2452 KB Output is correct
7 Correct 31 ms 2512 KB Output is correct
8 Correct 31 ms 2492 KB Output is correct
9 Correct 29 ms 2512 KB Output is correct
10 Correct 29 ms 2448 KB Output is correct
11 Correct 30 ms 2504 KB Output is correct
12 Correct 28 ms 2512 KB Output is correct
13 Correct 31 ms 2416 KB Output is correct
14 Correct 30 ms 2436 KB Output is correct
15 Correct 32 ms 2400 KB Output is correct
16 Correct 31 ms 2512 KB Output is correct
17 Correct 36 ms 2432 KB Output is correct
18 Correct 319 ms 16760 KB Output is correct
19 Correct 291 ms 16788 KB Output is correct
20 Correct 342 ms 16844 KB Output is correct
21 Correct 31 ms 2516 KB Output is correct
22 Correct 27 ms 2512 KB Output is correct
23 Correct 88 ms 8696 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 32 ms 2500 KB Output is correct
3 Correct 32 ms 2420 KB Output is correct
4 Correct 367 ms 16756 KB Output is correct
5 Correct 31 ms 2512 KB Output is correct
6 Correct 33 ms 2444 KB Output is correct
7 Correct 31 ms 2492 KB Output is correct
8 Correct 33 ms 2516 KB Output is correct
9 Correct 31 ms 2492 KB Output is correct
10 Correct 31 ms 2484 KB Output is correct
11 Correct 31 ms 2500 KB Output is correct
12 Correct 27 ms 2376 KB Output is correct
13 Correct 31 ms 2512 KB Output is correct
14 Correct 319 ms 16840 KB Output is correct
15 Correct 39 ms 2480 KB Output is correct
16 Correct 299 ms 16748 KB Output is correct
17 Correct 299 ms 16812 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 600 KB Output is correct
3 Correct 4 ms 600 KB Output is correct
4 Correct 0 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 0 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 33 ms 2496 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Incorrect 0 ms 212 KB Output isn't correct
21 Halted 0 ms 0 KB -