답안 #252087

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
252087 2020-07-24T06:11:48 Z jeqcho 이상한 기계 (APIO19_strange_device) C++17
100 / 100
587 ms 16760 KB
#include<bits/stdc++.h>
#define ll long long
#define N 1000005
 
using namespace std;
inline ll Get() {ll x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9') {if(ch=='-') f=-1;ch=getchar();}while('0'<=ch&&ch<='9') {x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}return x*f;}
 
int n;
ll A,B,len;
struct node {
    ll l,r;
    bool operator <(const node &a)const {
        if(l!=a.l) return l<a.l;
        return r<a.r;
    }
}s[N<<1];
ll gcd(ll a,ll b) {return !b?a:gcd(b,a%b);}
 
int main() {
    n=Get(),A=Get(),B=Get();
    for(int i=1;i<=n;i++) s[i].l=Get(),s[i].r=Get();
    ll g=gcd(A,B+1);
    ll ans=0;
    if((long double)A/g*B>1e18) {
        for(int i=1;i<=n;i++) ans+=s[i].r-s[i].l+1;
    } else {
        ll len=A/g*B;
        int tot=n;
        for(int i=1;i<=n;i++) {
            if(s[i].r-s[i].l+1>=len) {
                cout<<len;
                return 0;
            }
            s[i].l%=len,s[i].r%=len;
            if(s[i].l>s[i].r) {
                s[++tot].l=0,s[tot].r=s[i].r;
                s[i].r=len-1;
            }
        }
        sort(s+1,s+1+tot);
        ll last=-1;
        for(int i=1;i<=tot;i++) {
            if(s[i].r<last) continue ;
            ans+=s[i].r-max(s[i].l-1,last);
            last=s[i].r;
        }
    }
    cout<<ans;
    
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 57 ms 2040 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 0 ms 256 KB Output is correct
3 Correct 0 ms 256 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 340 ms 15992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 534 ms 16636 KB Output is correct
3 Correct 517 ms 16632 KB Output is correct
4 Correct 535 ms 16760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 534 ms 16636 KB Output is correct
3 Correct 517 ms 16632 KB Output is correct
4 Correct 535 ms 16760 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 514 ms 16540 KB Output is correct
7 Correct 518 ms 16612 KB Output is correct
8 Correct 521 ms 16760 KB Output is correct
9 Correct 556 ms 16760 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 534 ms 16636 KB Output is correct
3 Correct 517 ms 16632 KB Output is correct
4 Correct 535 ms 16760 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 54 ms 2040 KB Output is correct
7 Correct 54 ms 1912 KB Output is correct
8 Correct 50 ms 1912 KB Output is correct
9 Correct 51 ms 1912 KB Output is correct
10 Correct 53 ms 1812 KB Output is correct
11 Correct 53 ms 1912 KB Output is correct
12 Correct 51 ms 1912 KB Output is correct
13 Correct 53 ms 1912 KB Output is correct
14 Correct 53 ms 1912 KB Output is correct
15 Correct 56 ms 1912 KB Output is correct
16 Correct 55 ms 1912 KB Output is correct
17 Correct 52 ms 1912 KB Output is correct
18 Correct 524 ms 16080 KB Output is correct
19 Correct 508 ms 16028 KB Output is correct
20 Correct 569 ms 15992 KB Output is correct
21 Correct 58 ms 1912 KB Output is correct
22 Correct 48 ms 1916 KB Output is correct
23 Correct 162 ms 5624 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 56 ms 1912 KB Output is correct
3 Correct 54 ms 1912 KB Output is correct
4 Correct 587 ms 16120 KB Output is correct
5 Correct 53 ms 1912 KB Output is correct
6 Correct 54 ms 1912 KB Output is correct
7 Correct 54 ms 1912 KB Output is correct
8 Correct 55 ms 1912 KB Output is correct
9 Correct 62 ms 1912 KB Output is correct
10 Correct 55 ms 1912 KB Output is correct
11 Correct 55 ms 1920 KB Output is correct
12 Correct 49 ms 1912 KB Output is correct
13 Correct 54 ms 1912 KB Output is correct
14 Correct 565 ms 16120 KB Output is correct
15 Correct 54 ms 1912 KB Output is correct
16 Correct 515 ms 15992 KB Output is correct
17 Correct 513 ms 15992 KB Output is correct
18 Correct 0 ms 256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 256 KB Output is correct
2 Correct 5 ms 512 KB Output is correct
3 Correct 6 ms 512 KB Output is correct
4 Correct 0 ms 256 KB Output is correct
5 Correct 0 ms 256 KB Output is correct
6 Correct 0 ms 256 KB Output is correct
7 Correct 0 ms 384 KB Output is correct
8 Correct 0 ms 256 KB Output is correct
9 Correct 0 ms 256 KB Output is correct
10 Correct 0 ms 256 KB Output is correct
11 Correct 0 ms 256 KB Output is correct
12 Correct 0 ms 256 KB Output is correct
13 Correct 0 ms 256 KB Output is correct
14 Correct 0 ms 256 KB Output is correct
15 Correct 0 ms 384 KB Output is correct
16 Correct 5 ms 512 KB Output is correct
17 Correct 57 ms 2040 KB Output is correct
18 Correct 0 ms 384 KB Output is correct
19 Correct 0 ms 256 KB Output is correct
20 Correct 0 ms 256 KB Output is correct
21 Correct 0 ms 256 KB Output is correct
22 Correct 0 ms 256 KB Output is correct
23 Correct 0 ms 256 KB Output is correct
24 Correct 0 ms 256 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 1 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 340 ms 15992 KB Output is correct
29 Correct 0 ms 256 KB Output is correct
30 Correct 534 ms 16636 KB Output is correct
31 Correct 517 ms 16632 KB Output is correct
32 Correct 535 ms 16760 KB Output is correct
33 Correct 0 ms 256 KB Output is correct
34 Correct 514 ms 16540 KB Output is correct
35 Correct 518 ms 16612 KB Output is correct
36 Correct 521 ms 16760 KB Output is correct
37 Correct 556 ms 16760 KB Output is correct
38 Correct 0 ms 256 KB Output is correct
39 Correct 54 ms 2040 KB Output is correct
40 Correct 54 ms 1912 KB Output is correct
41 Correct 50 ms 1912 KB Output is correct
42 Correct 51 ms 1912 KB Output is correct
43 Correct 53 ms 1812 KB Output is correct
44 Correct 53 ms 1912 KB Output is correct
45 Correct 51 ms 1912 KB Output is correct
46 Correct 53 ms 1912 KB Output is correct
47 Correct 53 ms 1912 KB Output is correct
48 Correct 56 ms 1912 KB Output is correct
49 Correct 55 ms 1912 KB Output is correct
50 Correct 52 ms 1912 KB Output is correct
51 Correct 524 ms 16080 KB Output is correct
52 Correct 508 ms 16028 KB Output is correct
53 Correct 569 ms 15992 KB Output is correct
54 Correct 58 ms 1912 KB Output is correct
55 Correct 48 ms 1916 KB Output is correct
56 Correct 162 ms 5624 KB Output is correct
57 Correct 0 ms 256 KB Output is correct
58 Correct 56 ms 1912 KB Output is correct
59 Correct 54 ms 1912 KB Output is correct
60 Correct 587 ms 16120 KB Output is correct
61 Correct 53 ms 1912 KB Output is correct
62 Correct 54 ms 1912 KB Output is correct
63 Correct 54 ms 1912 KB Output is correct
64 Correct 55 ms 1912 KB Output is correct
65 Correct 62 ms 1912 KB Output is correct
66 Correct 55 ms 1912 KB Output is correct
67 Correct 55 ms 1920 KB Output is correct
68 Correct 49 ms 1912 KB Output is correct
69 Correct 54 ms 1912 KB Output is correct
70 Correct 565 ms 16120 KB Output is correct
71 Correct 54 ms 1912 KB Output is correct
72 Correct 515 ms 15992 KB Output is correct
73 Correct 513 ms 15992 KB Output is correct
74 Correct 0 ms 256 KB Output is correct
75 Correct 0 ms 256 KB Output is correct
76 Correct 0 ms 256 KB Output is correct
77 Correct 0 ms 256 KB Output is correct
78 Correct 0 ms 256 KB Output is correct
79 Correct 5 ms 512 KB Output is correct
80 Correct 584 ms 16064 KB Output is correct
81 Correct 586 ms 16148 KB Output is correct
82 Correct 561 ms 15992 KB Output is correct
83 Correct 563 ms 16120 KB Output is correct
84 Correct 562 ms 16120 KB Output is correct
85 Correct 555 ms 15992 KB Output is correct
86 Correct 158 ms 5752 KB Output is correct
87 Correct 0 ms 256 KB Output is correct