Submission #782512

# Submission time Handle Problem Language Result Execution time Memory
782512 2023-07-14T03:42:29 Z kebine Strange Device (APIO19_strange_device) C++17
100 / 100
360 ms 18968 KB
#include <bits/stdc++.h>
using namespace std;
 
#define v          vector
#define int        unsigned long long
#define all(a)     (a).begin(), (a).end()
#define pb         push_back
#define mk         make_pair
#define pii        pair<int, int>
#define ff         first
#define ss         second
#define inp_v(vec) for (auto &i : vec) cin >> i;
#define prt_v(vec) for (auto i : vec) cout << i << endl;
#define MS(x)     memset(x, 0, sizeof(x))
#define gcd(a,b)   __gcd(a, b);
#define lcm(a,b)   (a*(b/gcd(a,b)))
#define lb         lower_bound
#define ub         upper_bound
bool chmin(int &a, int b){return b<a?a=b, true:false;}
bool chmax(int &a, int b){return b>a?a=b, true:false;}
// bool comp(const pair<int, int>&a, const pair<int int>&b){
//     return a.second<b.second;
// }
signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, a, b;cin>>N>>a>>b;
    double cycles=a/(__gcd(a, b+1))*b;
    int cycle=(int)cycles;
    vector<pair<int, int>>segment;
    vector<pair<int, int>>seg;
    bool flag=false;
    for(int i=0;i<N;i++){
        int x, y;cin>>x>>y;
        if(y-x+1>=cycle){
            flag=true;
        }
        if(y>=cycle){
            // cout<<i<<" "<<x<<" "<<cycle<<" "<<y%cycle<<endl;
            if(x>=cycle){
                if(y/cycle>x/cycle){
                    segment.push_back({x%cycle, cycle-1});
                    segment.push_back({0, y%cycle});
                }
                else segment.push_back({x%cycle, y%cycle});
                // segment.push_back({0, y%cycle});
            }
            else{
                segment.push_back({x, cycle-1});
                segment.push_back({0, y%cycle});
            }
        }
        else{
            segment.push_back({x, y});
        }
    }
    sort(segment.begin(), segment.end());
    int curl=segment[0].first, curr=segment[0].second;
    int ans=curr-curl+1;
    // cout<<cycle<<endl;
    for(int i=1;i<segment.size();i++){
        // cout<<segment[i].first<<" "<<segment[i].second<<endl;
        if(curr>=segment[i].second){
            continue;
        }
        else{
            curl=max(curr+1, segment[i].first);
            curr=segment[i].second;
            ans+=curr-curl+1;
        }
    }
    if(flag)cout<<cycle<<endl;
    else cout<<ans<<endl;

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 3 ms 600 KB Output is correct
3 Correct 3 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 1 ms 212 KB Output is correct
9 Correct 1 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 1 ms 212 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 40 ms 2512 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 1 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 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 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 210 ms 16872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 303 ms 16868 KB Output is correct
3 Correct 300 ms 16840 KB Output is correct
4 Correct 288 ms 16780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 303 ms 16868 KB Output is correct
3 Correct 300 ms 16840 KB Output is correct
4 Correct 288 ms 16780 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 289 ms 16768 KB Output is correct
7 Correct 312 ms 16816 KB Output is correct
8 Correct 301 ms 16828 KB Output is correct
9 Correct 308 ms 16872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 303 ms 16868 KB Output is correct
3 Correct 300 ms 16840 KB Output is correct
4 Correct 288 ms 16780 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 29 ms 2412 KB Output is correct
7 Correct 30 ms 2512 KB Output is correct
8 Correct 28 ms 2512 KB Output is correct
9 Correct 30 ms 2428 KB Output is correct
10 Correct 27 ms 2468 KB Output is correct
11 Correct 36 ms 2512 KB Output is correct
12 Correct 27 ms 2512 KB Output is correct
13 Correct 29 ms 2448 KB Output is correct
14 Correct 28 ms 2420 KB Output is correct
15 Correct 36 ms 2476 KB Output is correct
16 Correct 37 ms 2460 KB Output is correct
17 Correct 29 ms 2468 KB Output is correct
18 Correct 325 ms 16852 KB Output is correct
19 Correct 289 ms 16792 KB Output is correct
20 Correct 320 ms 16804 KB Output is correct
21 Correct 31 ms 2512 KB Output is correct
22 Correct 27 ms 2504 KB Output is correct
23 Correct 88 ms 8584 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 30 ms 2416 KB Output is correct
3 Correct 31 ms 2408 KB Output is correct
4 Correct 360 ms 16872 KB Output is correct
5 Correct 30 ms 2512 KB Output is correct
6 Correct 31 ms 2512 KB Output is correct
7 Correct 32 ms 2500 KB Output is correct
8 Correct 32 ms 2408 KB Output is correct
9 Correct 30 ms 2416 KB Output is correct
10 Correct 30 ms 2516 KB Output is correct
11 Correct 30 ms 2512 KB Output is correct
12 Correct 27 ms 2404 KB Output is correct
13 Correct 30 ms 2512 KB Output is correct
14 Correct 308 ms 16824 KB Output is correct
15 Correct 31 ms 2512 KB Output is correct
16 Correct 292 ms 16776 KB Output is correct
17 Correct 293 ms 16792 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 3 ms 600 KB Output is correct
3 Correct 3 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 1 ms 212 KB Output is correct
9 Correct 1 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 1 ms 212 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 40 ms 2512 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 0 ms 212 KB Output is correct
22 Correct 0 ms 212 KB Output is correct
23 Correct 0 ms 212 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 340 KB Output is correct
28 Correct 210 ms 16872 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 303 ms 16868 KB Output is correct
31 Correct 300 ms 16840 KB Output is correct
32 Correct 288 ms 16780 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 289 ms 16768 KB Output is correct
35 Correct 312 ms 16816 KB Output is correct
36 Correct 301 ms 16828 KB Output is correct
37 Correct 308 ms 16872 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 29 ms 2412 KB Output is correct
40 Correct 30 ms 2512 KB Output is correct
41 Correct 28 ms 2512 KB Output is correct
42 Correct 30 ms 2428 KB Output is correct
43 Correct 27 ms 2468 KB Output is correct
44 Correct 36 ms 2512 KB Output is correct
45 Correct 27 ms 2512 KB Output is correct
46 Correct 29 ms 2448 KB Output is correct
47 Correct 28 ms 2420 KB Output is correct
48 Correct 36 ms 2476 KB Output is correct
49 Correct 37 ms 2460 KB Output is correct
50 Correct 29 ms 2468 KB Output is correct
51 Correct 325 ms 16852 KB Output is correct
52 Correct 289 ms 16792 KB Output is correct
53 Correct 320 ms 16804 KB Output is correct
54 Correct 31 ms 2512 KB Output is correct
55 Correct 27 ms 2504 KB Output is correct
56 Correct 88 ms 8584 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 30 ms 2416 KB Output is correct
59 Correct 31 ms 2408 KB Output is correct
60 Correct 360 ms 16872 KB Output is correct
61 Correct 30 ms 2512 KB Output is correct
62 Correct 31 ms 2512 KB Output is correct
63 Correct 32 ms 2500 KB Output is correct
64 Correct 32 ms 2408 KB Output is correct
65 Correct 30 ms 2416 KB Output is correct
66 Correct 30 ms 2516 KB Output is correct
67 Correct 30 ms 2512 KB Output is correct
68 Correct 27 ms 2404 KB Output is correct
69 Correct 30 ms 2512 KB Output is correct
70 Correct 308 ms 16824 KB Output is correct
71 Correct 31 ms 2512 KB Output is correct
72 Correct 292 ms 16776 KB Output is correct
73 Correct 293 ms 16792 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 316 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 0 ms 212 KB Output is correct
78 Correct 1 ms 320 KB Output is correct
79 Correct 3 ms 968 KB Output is correct
80 Correct 356 ms 18956 KB Output is correct
81 Correct 348 ms 18696 KB Output is correct
82 Correct 343 ms 18400 KB Output is correct
83 Correct 332 ms 18428 KB Output is correct
84 Correct 356 ms 18860 KB Output is correct
85 Correct 322 ms 18968 KB Output is correct
86 Correct 89 ms 10424 KB Output is correct
87 Correct 0 ms 212 KB Output is correct