답안 #744208

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744208 2023-05-18T09:21:30 Z iamporrrrrrrrr 이상한 기계 (APIO19_strange_device) C++14
100 / 100
568 ms 37724 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;
set<int> s;
vector<pair<int,int>> v;
int g(int a,int b){
    if(b==0) return a;
    return g(b,a%b);
}
int st[1000010],ed[1000010];
signed main()
{
    ios::sync_with_stdio(0),cin.tie(0);
    int n,a,b;
    int sum=0;
    cin>>n>>a>>b;
    int dmod = g(max(a,b+1),min(a,b+1));
    for(int i=1;i<=n;i++){
        cin>>st[i]>>ed[i];
        sum+=ed[i]-st[i]+1;
    }
    if((double)(ed[n]/(a/dmod))<=(double)b){
        cout<<sum;
        return 0;
    }
    int mod=a/dmod*b;
    //cout<<mod<<' ';
    for(int i=1;i<=n;i++){
        int x=st[i];
        int y=ed[i];
        if(y-x>mod){
            cout<<mod;
            return 0;
        }
        x%=mod;
        y%=mod;
        if(y>=x){
            v.push_back({x,y});
        }
        else v.push_back({x,mod-1}),v.push_back({0,y});
    }
    sort(v.begin(),v.end());
    int rr=-1,ans=0;
    for(int i=0;i<v.size();i++){
        int l=v[i].first;
        int r=v[i].second;
        if(l>rr){
            ans+=(r-l+1);
            rr=r;
        }
        else if(l<=rr&&r>rr){
            ans+=(r-rr);
            rr=r;
        }
    }
    cout<<ans;
    return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:44:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 852 KB Output is correct
3 Correct 5 ms 1236 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 1236 KB Output is correct
17 Correct 45 ms 7792 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 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 380 KB Output is correct
5 Correct 306 ms 34540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 454 ms 32532 KB Output is correct
3 Correct 414 ms 34724 KB Output is correct
4 Correct 486 ms 37196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 454 ms 32532 KB Output is correct
3 Correct 414 ms 34724 KB Output is correct
4 Correct 486 ms 37196 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 416 ms 37388 KB Output is correct
7 Correct 568 ms 37700 KB Output is correct
8 Correct 433 ms 37260 KB Output is correct
9 Correct 461 ms 37724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 454 ms 32532 KB Output is correct
3 Correct 414 ms 34724 KB Output is correct
4 Correct 486 ms 37196 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 50 ms 7716 KB Output is correct
7 Correct 43 ms 7684 KB Output is correct
8 Correct 43 ms 7764 KB Output is correct
9 Correct 43 ms 7772 KB Output is correct
10 Correct 42 ms 7752 KB Output is correct
11 Correct 42 ms 7688 KB Output is correct
12 Correct 44 ms 7756 KB Output is correct
13 Correct 52 ms 7872 KB Output is correct
14 Correct 46 ms 7684 KB Output is correct
15 Correct 54 ms 7684 KB Output is correct
16 Correct 50 ms 7792 KB Output is correct
17 Correct 41 ms 7760 KB Output is correct
18 Correct 438 ms 36984 KB Output is correct
19 Correct 426 ms 37308 KB Output is correct
20 Correct 468 ms 37228 KB Output is correct
21 Correct 44 ms 7700 KB Output is correct
22 Correct 42 ms 7792 KB Output is correct
23 Correct 147 ms 18252 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 43 ms 4040 KB Output is correct
3 Correct 45 ms 7740 KB Output is correct
4 Correct 487 ms 37060 KB Output is correct
5 Correct 48 ms 7712 KB Output is correct
6 Correct 45 ms 7772 KB Output is correct
7 Correct 46 ms 7744 KB Output is correct
8 Correct 48 ms 7716 KB Output is correct
9 Correct 45 ms 7752 KB Output is correct
10 Correct 45 ms 7720 KB Output is correct
11 Correct 47 ms 7764 KB Output is correct
12 Correct 42 ms 7784 KB Output is correct
13 Correct 45 ms 7728 KB Output is correct
14 Correct 476 ms 36984 KB Output is correct
15 Correct 45 ms 7736 KB Output is correct
16 Correct 425 ms 36852 KB Output is correct
17 Correct 417 ms 37056 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 5 ms 852 KB Output is correct
3 Correct 5 ms 1236 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 336 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 340 KB Output is correct
16 Correct 5 ms 1236 KB Output is correct
17 Correct 45 ms 7792 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 0 ms 340 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 0 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 380 KB Output is correct
28 Correct 306 ms 34540 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 454 ms 32532 KB Output is correct
31 Correct 414 ms 34724 KB Output is correct
32 Correct 486 ms 37196 KB Output is correct
33 Correct 0 ms 340 KB Output is correct
34 Correct 416 ms 37388 KB Output is correct
35 Correct 568 ms 37700 KB Output is correct
36 Correct 433 ms 37260 KB Output is correct
37 Correct 461 ms 37724 KB Output is correct
38 Correct 1 ms 340 KB Output is correct
39 Correct 50 ms 7716 KB Output is correct
40 Correct 43 ms 7684 KB Output is correct
41 Correct 43 ms 7764 KB Output is correct
42 Correct 43 ms 7772 KB Output is correct
43 Correct 42 ms 7752 KB Output is correct
44 Correct 42 ms 7688 KB Output is correct
45 Correct 44 ms 7756 KB Output is correct
46 Correct 52 ms 7872 KB Output is correct
47 Correct 46 ms 7684 KB Output is correct
48 Correct 54 ms 7684 KB Output is correct
49 Correct 50 ms 7792 KB Output is correct
50 Correct 41 ms 7760 KB Output is correct
51 Correct 438 ms 36984 KB Output is correct
52 Correct 426 ms 37308 KB Output is correct
53 Correct 468 ms 37228 KB Output is correct
54 Correct 44 ms 7700 KB Output is correct
55 Correct 42 ms 7792 KB Output is correct
56 Correct 147 ms 18252 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 43 ms 4040 KB Output is correct
59 Correct 45 ms 7740 KB Output is correct
60 Correct 487 ms 37060 KB Output is correct
61 Correct 48 ms 7712 KB Output is correct
62 Correct 45 ms 7772 KB Output is correct
63 Correct 46 ms 7744 KB Output is correct
64 Correct 48 ms 7716 KB Output is correct
65 Correct 45 ms 7752 KB Output is correct
66 Correct 45 ms 7720 KB Output is correct
67 Correct 47 ms 7764 KB Output is correct
68 Correct 42 ms 7784 KB Output is correct
69 Correct 45 ms 7728 KB Output is correct
70 Correct 476 ms 36984 KB Output is correct
71 Correct 45 ms 7736 KB Output is correct
72 Correct 425 ms 36852 KB Output is correct
73 Correct 417 ms 37056 KB Output is correct
74 Correct 1 ms 340 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 340 KB Output is correct
77 Correct 1 ms 340 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 5 ms 1256 KB Output is correct
80 Correct 494 ms 37672 KB Output is correct
81 Correct 487 ms 37288 KB Output is correct
82 Correct 479 ms 37328 KB Output is correct
83 Correct 452 ms 37168 KB Output is correct
84 Correct 452 ms 37164 KB Output is correct
85 Correct 445 ms 37172 KB Output is correct
86 Correct 142 ms 18540 KB Output is correct
87 Correct 1 ms 340 KB Output is correct