답안 #729408

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
729408 2023-04-24T03:39:29 Z 1075508020060209tc 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1362 ms 69764 KB
#include<bits/stdc++.h>

using namespace std;
#define int long long
int n;int A;int B;
int MX=2e18;
int ar[1000006];int br[1000006];


map<pair<int,int>,int>vis;

signed main(){
cin>>n>>A>>B;
for(int i=1;i<=n;i++){
    cin>>ar[i]>>br[i];
}
int ta=A;

if(B<=MX/(ta/__gcd(ta,B+1))){
    A=B*A/__gcd(A,B+1);
}else{
    A=MX;
}





vector<pair<int,int>>seg;
for(int i=1;i<=n;i++){
    if(br[i]-ar[i]+1>=A){
        cout<<A;return 0;
    }
    int l=ar[i]%A;int r=br[i]%A;
    if(r<l){
        seg.push_back({l,A-1});
        seg.push_back({0,r});
    }else{
        seg.push_back({l,r});
    }
}
sort(seg.begin(),seg.end());
int ans=0;
int rpl=seg[0].second;
int lpl=seg[0].first;
for(int i=1;i<seg.size();i++){

    if(seg[i].first<=rpl+1){
        rpl=max(rpl,seg[i].second);
        continue;
    }else{
        ans+=rpl-lpl+1;
        lpl=seg[i].first;rpl=seg[i].second;
    }
}
ans+=rpl-lpl+1;
cout<<ans<<endl;

}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:46:14: 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]
   46 | for(int i=1;i<seg.size();i++){
      |             ~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 14 ms 1092 KB Output is correct
3 Correct 14 ms 1100 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 14 ms 1068 KB Output is correct
17 Correct 133 ms 4560 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 0 ms 312 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 304 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 364 KB Output is correct
3 Correct 2 ms 468 KB Output is correct
4 Correct 2 ms 324 KB Output is correct
5 Correct 935 ms 32572 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1360 ms 32664 KB Output is correct
3 Correct 1332 ms 32564 KB Output is correct
4 Correct 1300 ms 32764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1360 ms 32664 KB Output is correct
3 Correct 1332 ms 32564 KB Output is correct
4 Correct 1300 ms 32764 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1264 ms 32740 KB Output is correct
7 Correct 1268 ms 32504 KB Output is correct
8 Correct 1235 ms 32612 KB Output is correct
9 Correct 1277 ms 32532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1360 ms 32664 KB Output is correct
3 Correct 1332 ms 32564 KB Output is correct
4 Correct 1300 ms 32764 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 129 ms 4416 KB Output is correct
7 Correct 129 ms 4824 KB Output is correct
8 Correct 138 ms 4824 KB Output is correct
9 Correct 129 ms 4836 KB Output is correct
10 Correct 130 ms 4772 KB Output is correct
11 Correct 132 ms 4760 KB Output is correct
12 Correct 132 ms 4984 KB Output is correct
13 Correct 129 ms 4716 KB Output is correct
14 Correct 126 ms 4820 KB Output is correct
15 Correct 133 ms 4768 KB Output is correct
16 Correct 132 ms 4820 KB Output is correct
17 Correct 128 ms 4712 KB Output is correct
18 Correct 1270 ms 32516 KB Output is correct
19 Correct 1267 ms 32524 KB Output is correct
20 Correct 1290 ms 32468 KB Output is correct
21 Correct 133 ms 4964 KB Output is correct
22 Correct 127 ms 4764 KB Output is correct
23 Correct 418 ms 14656 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 308 KB Output is correct
2 Correct 134 ms 4352 KB Output is correct
3 Correct 127 ms 4588 KB Output is correct
4 Correct 1326 ms 32588 KB Output is correct
5 Correct 132 ms 4504 KB Output is correct
6 Correct 129 ms 4488 KB Output is correct
7 Correct 129 ms 4560 KB Output is correct
8 Correct 136 ms 4460 KB Output is correct
9 Correct 131 ms 4572 KB Output is correct
10 Correct 133 ms 4544 KB Output is correct
11 Correct 130 ms 4552 KB Output is correct
12 Correct 125 ms 4500 KB Output is correct
13 Correct 137 ms 4468 KB Output is correct
14 Correct 1290 ms 32564 KB Output is correct
15 Correct 127 ms 4544 KB Output is correct
16 Correct 1267 ms 32504 KB Output is correct
17 Correct 1247 ms 32468 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 14 ms 1092 KB Output is correct
3 Correct 14 ms 1100 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 308 KB Output is correct
7 Correct 1 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 1 ms 212 KB Output is correct
11 Correct 1 ms 212 KB Output is correct
12 Correct 1 ms 304 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 14 ms 1068 KB Output is correct
17 Correct 133 ms 4560 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 1 ms 304 KB Output is correct
21 Correct 0 ms 312 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 304 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 2 ms 364 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 2 ms 324 KB Output is correct
28 Correct 935 ms 32572 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 1360 ms 32664 KB Output is correct
31 Correct 1332 ms 32564 KB Output is correct
32 Correct 1300 ms 32764 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 1264 ms 32740 KB Output is correct
35 Correct 1268 ms 32504 KB Output is correct
36 Correct 1235 ms 32612 KB Output is correct
37 Correct 1277 ms 32532 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 129 ms 4416 KB Output is correct
40 Correct 129 ms 4824 KB Output is correct
41 Correct 138 ms 4824 KB Output is correct
42 Correct 129 ms 4836 KB Output is correct
43 Correct 130 ms 4772 KB Output is correct
44 Correct 132 ms 4760 KB Output is correct
45 Correct 132 ms 4984 KB Output is correct
46 Correct 129 ms 4716 KB Output is correct
47 Correct 126 ms 4820 KB Output is correct
48 Correct 133 ms 4768 KB Output is correct
49 Correct 132 ms 4820 KB Output is correct
50 Correct 128 ms 4712 KB Output is correct
51 Correct 1270 ms 32516 KB Output is correct
52 Correct 1267 ms 32524 KB Output is correct
53 Correct 1290 ms 32468 KB Output is correct
54 Correct 133 ms 4964 KB Output is correct
55 Correct 127 ms 4764 KB Output is correct
56 Correct 418 ms 14656 KB Output is correct
57 Correct 0 ms 308 KB Output is correct
58 Correct 134 ms 4352 KB Output is correct
59 Correct 127 ms 4588 KB Output is correct
60 Correct 1326 ms 32588 KB Output is correct
61 Correct 132 ms 4504 KB Output is correct
62 Correct 129 ms 4488 KB Output is correct
63 Correct 129 ms 4560 KB Output is correct
64 Correct 136 ms 4460 KB Output is correct
65 Correct 131 ms 4572 KB Output is correct
66 Correct 133 ms 4544 KB Output is correct
67 Correct 130 ms 4552 KB Output is correct
68 Correct 125 ms 4500 KB Output is correct
69 Correct 137 ms 4468 KB Output is correct
70 Correct 1290 ms 32564 KB Output is correct
71 Correct 127 ms 4544 KB Output is correct
72 Correct 1267 ms 32504 KB Output is correct
73 Correct 1247 ms 32468 KB Output is correct
74 Correct 1 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 308 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 312 KB Output is correct
79 Correct 13 ms 1240 KB Output is correct
80 Correct 1360 ms 69588 KB Output is correct
81 Correct 1362 ms 69636 KB Output is correct
82 Correct 1344 ms 69556 KB Output is correct
83 Correct 1317 ms 69736 KB Output is correct
84 Correct 1335 ms 69664 KB Output is correct
85 Correct 1294 ms 69764 KB Output is correct
86 Correct 428 ms 26516 KB Output is correct
87 Correct 1 ms 212 KB Output is correct