답안 #781905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
781905 2023-07-13T13:02:04 Z makanhulia 이상한 기계 (APIO19_strange_device) C++17
100 / 100
376 ms 18580 KB
#include <bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define keish                             ios_base::sync_with_stdio(0);       cin.tie(0); cout.tie(0)
      
using namespace std;

int n, a, b, l, r;

signed main(){
      keish;
      cin >> n >> a >> b;

      int c = a / gcd(a, b + 1);
      if(c > 1e18 / b) c = 1e18;
      else c *= b;
      
      vector<pair<int, int>> v;
      bool ok = 0;
      for(int i = 0; i < n; i++){
            cin >> l >> r;
            if(r - l + 1 >= c){
                  ok = 1;
            }

            l %= c, r %= c;

            if(l <= r){
                  v.push_back({l, r});
            }else{
                  v.push_back({l, c - 1});
                  v.push_back({0, r});
            }
      }

      if(ok){
            cout << c << '\n';
            return 0;
      }

      sort(v.begin(), v.end());

      int lf = v[0].fi, rg = v[0].se;
      int ans = 0;
      for(int i = 1; i < v.size(); i++){
            if(v[i].fi > rg){
                  ans += rg - lf + 1;
                  lf = v[i].fi, rg = v[i].se;
            }
            rg = max(rg, v[i].se);
      }
      ans += rg - lf + 1;

      cout << ans << '\n';
}     

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:46:24: 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 < v.size(); i++){
      |                      ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 684 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 0 ms 212 KB Output is correct
10 Correct 1 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 0 ms 212 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 39 ms 2816 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 0 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 1 ms 212 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 340 KB Output is correct
5 Correct 216 ms 17124 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 322 ms 17072 KB Output is correct
3 Correct 302 ms 16856 KB Output is correct
4 Correct 295 ms 16792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 322 ms 17072 KB Output is correct
3 Correct 302 ms 16856 KB Output is correct
4 Correct 295 ms 16792 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 337 ms 16816 KB Output is correct
7 Correct 315 ms 16864 KB Output is correct
8 Correct 307 ms 16832 KB Output is correct
9 Correct 331 ms 16804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 322 ms 17072 KB Output is correct
3 Correct 302 ms 16856 KB Output is correct
4 Correct 295 ms 16792 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 39 ms 2408 KB Output is correct
7 Correct 34 ms 2576 KB Output is correct
8 Correct 33 ms 2468 KB Output is correct
9 Correct 32 ms 2592 KB Output is correct
10 Correct 31 ms 2512 KB Output is correct
11 Correct 32 ms 2452 KB Output is correct
12 Correct 32 ms 2512 KB Output is correct
13 Correct 32 ms 2768 KB Output is correct
14 Correct 31 ms 2500 KB Output is correct
15 Correct 45 ms 2504 KB Output is correct
16 Correct 34 ms 2456 KB Output is correct
17 Correct 32 ms 2644 KB Output is correct
18 Correct 335 ms 16768 KB Output is correct
19 Correct 292 ms 16812 KB Output is correct
20 Correct 347 ms 16880 KB Output is correct
21 Correct 33 ms 2700 KB Output is correct
22 Correct 31 ms 2564 KB Output is correct
23 Correct 92 ms 9020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 35 ms 2604 KB Output is correct
3 Correct 33 ms 2648 KB Output is correct
4 Correct 355 ms 16868 KB Output is correct
5 Correct 33 ms 2508 KB Output is correct
6 Correct 34 ms 2612 KB Output is correct
7 Correct 32 ms 2660 KB Output is correct
8 Correct 34 ms 2548 KB Output is correct
9 Correct 41 ms 2472 KB Output is correct
10 Correct 33 ms 2544 KB Output is correct
11 Correct 34 ms 2596 KB Output is correct
12 Correct 29 ms 2472 KB Output is correct
13 Correct 32 ms 2424 KB Output is correct
14 Correct 325 ms 16864 KB Output is correct
15 Correct 35 ms 2580 KB Output is correct
16 Correct 303 ms 16872 KB Output is correct
17 Correct 307 ms 16776 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 3 ms 684 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 0 ms 212 KB Output is correct
10 Correct 1 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 0 ms 212 KB Output is correct
16 Correct 3 ms 600 KB Output is correct
17 Correct 39 ms 2816 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 212 KB Output is correct
20 Correct 0 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 1 ms 212 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 340 KB Output is correct
28 Correct 216 ms 17124 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 322 ms 17072 KB Output is correct
31 Correct 302 ms 16856 KB Output is correct
32 Correct 295 ms 16792 KB Output is correct
33 Correct 0 ms 212 KB Output is correct
34 Correct 337 ms 16816 KB Output is correct
35 Correct 315 ms 16864 KB Output is correct
36 Correct 307 ms 16832 KB Output is correct
37 Correct 331 ms 16804 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 39 ms 2408 KB Output is correct
40 Correct 34 ms 2576 KB Output is correct
41 Correct 33 ms 2468 KB Output is correct
42 Correct 32 ms 2592 KB Output is correct
43 Correct 31 ms 2512 KB Output is correct
44 Correct 32 ms 2452 KB Output is correct
45 Correct 32 ms 2512 KB Output is correct
46 Correct 32 ms 2768 KB Output is correct
47 Correct 31 ms 2500 KB Output is correct
48 Correct 45 ms 2504 KB Output is correct
49 Correct 34 ms 2456 KB Output is correct
50 Correct 32 ms 2644 KB Output is correct
51 Correct 335 ms 16768 KB Output is correct
52 Correct 292 ms 16812 KB Output is correct
53 Correct 347 ms 16880 KB Output is correct
54 Correct 33 ms 2700 KB Output is correct
55 Correct 31 ms 2564 KB Output is correct
56 Correct 92 ms 9020 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 35 ms 2604 KB Output is correct
59 Correct 33 ms 2648 KB Output is correct
60 Correct 355 ms 16868 KB Output is correct
61 Correct 33 ms 2508 KB Output is correct
62 Correct 34 ms 2612 KB Output is correct
63 Correct 32 ms 2660 KB Output is correct
64 Correct 34 ms 2548 KB Output is correct
65 Correct 41 ms 2472 KB Output is correct
66 Correct 33 ms 2544 KB Output is correct
67 Correct 34 ms 2596 KB Output is correct
68 Correct 29 ms 2472 KB Output is correct
69 Correct 32 ms 2424 KB Output is correct
70 Correct 325 ms 16864 KB Output is correct
71 Correct 35 ms 2580 KB Output is correct
72 Correct 303 ms 16872 KB Output is correct
73 Correct 307 ms 16776 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 320 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 4 ms 984 KB Output is correct
80 Correct 369 ms 18496 KB Output is correct
81 Correct 376 ms 17876 KB Output is correct
82 Correct 351 ms 18580 KB Output is correct
83 Correct 335 ms 18392 KB Output is correct
84 Correct 335 ms 18340 KB Output is correct
85 Correct 334 ms 18336 KB Output is correct
86 Correct 97 ms 10772 KB Output is correct
87 Correct 1 ms 316 KB Output is correct