Submission #972561

# Submission time Handle Problem Language Result Execution time Memory
972561 2024-04-30T15:08:59 Z simona1230 Strange Device (APIO19_strange_device) C++17
100 / 100
358 ms 54440 KB
#include <bits/stdc++.h>

using namespace std;
long long n,a,b;
pair<long long,long long> p[2000001];
void solve()
{
    int cnt=n;
    long long h=1e18+1;
    a/=__gcd(a,b+1);
    if(1e18/a>=b)h=b*a;
    //cout<<h<<endl;
    for(long long i=1;i<=n;i++)
    {
        long long l,r;
        cin>>l>>r;
        if(r-l+1>=h)
        {
            cout<<h<<endl;
            return;
        }
        p[i]={l%(h),r%(h)};
        if(p[i].first>p[i].second)
        {
            cnt++;
            p[cnt].first=0;
            p[cnt].second=p[i].second;

            p[i].second=h-1;
        }
    }
    long long ans=0;
    sort(p+1,p+cnt+1);

    long long r=-1;
    for(long long i=1;i<=cnt;i++)
    {
        if(p[i].second>r)
        {
            if(p[i].first>r)
                ans+=p[i].second-p[i].first+1;
            else ans+=p[i].second-r;
        }

        r=max(r,p[i].second);
    }

    cout<<ans<<endl;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>a>>b;
	solve();
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 5 ms 860 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 472 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 1 ms 348 KB Output is correct
16 Correct 4 ms 840 KB Output is correct
17 Correct 33 ms 6260 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 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 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 196 ms 42096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 289 ms 54008 KB Output is correct
3 Correct 281 ms 54144 KB Output is correct
4 Correct 311 ms 54140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 289 ms 54008 KB Output is correct
3 Correct 281 ms 54144 KB Output is correct
4 Correct 311 ms 54140 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 292 ms 54000 KB Output is correct
7 Correct 313 ms 54016 KB Output is correct
8 Correct 302 ms 54148 KB Output is correct
9 Correct 326 ms 54096 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 289 ms 54008 KB Output is correct
3 Correct 281 ms 54144 KB Output is correct
4 Correct 311 ms 54140 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 30 ms 6396 KB Output is correct
7 Correct 29 ms 6244 KB Output is correct
8 Correct 30 ms 6824 KB Output is correct
9 Correct 36 ms 6256 KB Output is correct
10 Correct 42 ms 6260 KB Output is correct
11 Correct 30 ms 6388 KB Output is correct
12 Correct 28 ms 6228 KB Output is correct
13 Correct 30 ms 6228 KB Output is correct
14 Correct 29 ms 6224 KB Output is correct
15 Correct 32 ms 6236 KB Output is correct
16 Correct 39 ms 6236 KB Output is correct
17 Correct 29 ms 6260 KB Output is correct
18 Correct 291 ms 53988 KB Output is correct
19 Correct 281 ms 54148 KB Output is correct
20 Correct 336 ms 54132 KB Output is correct
21 Correct 31 ms 6232 KB Output is correct
22 Correct 27 ms 6228 KB Output is correct
23 Correct 84 ms 19284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 32 ms 6384 KB Output is correct
3 Correct 32 ms 6236 KB Output is correct
4 Correct 347 ms 54128 KB Output is correct
5 Correct 30 ms 6344 KB Output is correct
6 Correct 31 ms 6236 KB Output is correct
7 Correct 31 ms 6260 KB Output is correct
8 Correct 39 ms 6228 KB Output is correct
9 Correct 34 ms 6256 KB Output is correct
10 Correct 30 ms 6224 KB Output is correct
11 Correct 31 ms 6264 KB Output is correct
12 Correct 26 ms 6644 KB Output is correct
13 Correct 30 ms 6392 KB Output is correct
14 Correct 317 ms 54128 KB Output is correct
15 Correct 31 ms 6236 KB Output is correct
16 Correct 286 ms 53968 KB Output is correct
17 Correct 292 ms 54112 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Correct 5 ms 856 KB Output is correct
3 Correct 5 ms 860 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 344 KB Output is correct
8 Correct 1 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 472 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 1 ms 348 KB Output is correct
16 Correct 4 ms 840 KB Output is correct
17 Correct 33 ms 6260 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 196 ms 42096 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 289 ms 54008 KB Output is correct
31 Correct 281 ms 54144 KB Output is correct
32 Correct 311 ms 54140 KB Output is correct
33 Correct 0 ms 348 KB Output is correct
34 Correct 292 ms 54000 KB Output is correct
35 Correct 313 ms 54016 KB Output is correct
36 Correct 302 ms 54148 KB Output is correct
37 Correct 326 ms 54096 KB Output is correct
38 Correct 0 ms 348 KB Output is correct
39 Correct 30 ms 6396 KB Output is correct
40 Correct 29 ms 6244 KB Output is correct
41 Correct 30 ms 6824 KB Output is correct
42 Correct 36 ms 6256 KB Output is correct
43 Correct 42 ms 6260 KB Output is correct
44 Correct 30 ms 6388 KB Output is correct
45 Correct 28 ms 6228 KB Output is correct
46 Correct 30 ms 6228 KB Output is correct
47 Correct 29 ms 6224 KB Output is correct
48 Correct 32 ms 6236 KB Output is correct
49 Correct 39 ms 6236 KB Output is correct
50 Correct 29 ms 6260 KB Output is correct
51 Correct 291 ms 53988 KB Output is correct
52 Correct 281 ms 54148 KB Output is correct
53 Correct 336 ms 54132 KB Output is correct
54 Correct 31 ms 6232 KB Output is correct
55 Correct 27 ms 6228 KB Output is correct
56 Correct 84 ms 19284 KB Output is correct
57 Correct 0 ms 348 KB Output is correct
58 Correct 32 ms 6384 KB Output is correct
59 Correct 32 ms 6236 KB Output is correct
60 Correct 347 ms 54128 KB Output is correct
61 Correct 30 ms 6344 KB Output is correct
62 Correct 31 ms 6236 KB Output is correct
63 Correct 31 ms 6260 KB Output is correct
64 Correct 39 ms 6228 KB Output is correct
65 Correct 34 ms 6256 KB Output is correct
66 Correct 30 ms 6224 KB Output is correct
67 Correct 31 ms 6264 KB Output is correct
68 Correct 26 ms 6644 KB Output is correct
69 Correct 30 ms 6392 KB Output is correct
70 Correct 317 ms 54128 KB Output is correct
71 Correct 31 ms 6236 KB Output is correct
72 Correct 286 ms 53968 KB Output is correct
73 Correct 292 ms 54112 KB Output is correct
74 Correct 0 ms 348 KB Output is correct
75 Correct 1 ms 348 KB Output is correct
76 Correct 0 ms 348 KB Output is correct
77 Correct 0 ms 344 KB Output is correct
78 Correct 0 ms 348 KB Output is correct
79 Correct 3 ms 860 KB Output is correct
80 Correct 347 ms 54028 KB Output is correct
81 Correct 345 ms 54232 KB Output is correct
82 Correct 358 ms 54096 KB Output is correct
83 Correct 318 ms 54440 KB Output is correct
84 Correct 321 ms 54100 KB Output is correct
85 Correct 339 ms 54384 KB Output is correct
86 Correct 86 ms 19200 KB Output is correct
87 Correct 1 ms 348 KB Output is correct