답안 #519139

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519139 2022-01-25T18:09:34 Z cadmiumsky 이상한 기계 (APIO19_strange_device) C++14
100 / 100
1743 ms 100288 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
  int a,b,q;
  bool ok = 0;
  cin >> q >> a >> b;
  map<int,int> smen;
  int per = a * b / __gcd(b + 1, a); // formula magica care e motivata din.. niste calcule de clasa a 7a de algebra modulara O_o
  if(log10((double)a / (double)__gcd(b + 1, a)) + log10(b) >= 18)
    per = 1e18 + 1;
  for(int i = 0, cl, cr, l, r; i < q; i ++) {
    cin >> l >> r;
    cl = per * (l / per + 1);
    cr = per * (r / per);
    if(cl < cr) {
      ok = 1;
    }
    if(cl == cr) {
      l %= per;
      r %= per;
      smen[l]++;
      smen[0]++;
      smen[r + 1]--;
      //cout << l <<  ' '<< per - 1 << '\n' << 0 << ' ' << r << '\n';
    }
    else {
      l %= per;
      r %= per;
      smen[l]++;
      smen[r + 1]--;
      //cout << l << ' ' << r << '\n';
    }
  }
  if(ok) {
    cout << per << '\n';
    return 0;
  }
  smen[per];
  int total = 0, cnt = 0, last = -1;
  for(auto x : smen) {
    if(last != x.first && cnt > 0)
      total += x.first - last;
    if(x.first >= per)
      break;
    //cout << x.first <<  ' '<< x.second << '\n';
    cnt += x.second;
    last = x.first;
  }
  cout << total << '\n';
}

# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 16 ms 840 KB Output is correct
3 Correct 25 ms 832 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 284 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 15 ms 1232 KB Output is correct
17 Correct 179 ms 10168 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 2 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 930 ms 25496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1553 ms 62832 KB Output is correct
3 Correct 1568 ms 62948 KB Output is correct
4 Correct 1682 ms 62992 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1553 ms 62832 KB Output is correct
3 Correct 1568 ms 62948 KB Output is correct
4 Correct 1682 ms 62992 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1599 ms 62864 KB Output is correct
7 Correct 1618 ms 62892 KB Output is correct
8 Correct 1670 ms 62844 KB Output is correct
9 Correct 1743 ms 62824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1553 ms 62832 KB Output is correct
3 Correct 1568 ms 62948 KB Output is correct
4 Correct 1682 ms 62992 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 142 ms 6500 KB Output is correct
7 Correct 151 ms 6436 KB Output is correct
8 Correct 150 ms 6468 KB Output is correct
9 Correct 149 ms 6488 KB Output is correct
10 Correct 143 ms 6508 KB Output is correct
11 Correct 169 ms 6508 KB Output is correct
12 Correct 142 ms 6480 KB Output is correct
13 Correct 150 ms 6448 KB Output is correct
14 Correct 151 ms 6564 KB Output is correct
15 Correct 153 ms 6444 KB Output is correct
16 Correct 153 ms 6600 KB Output is correct
17 Correct 152 ms 6600 KB Output is correct
18 Correct 1516 ms 62896 KB Output is correct
19 Correct 1578 ms 62920 KB Output is correct
20 Correct 1645 ms 62920 KB Output is correct
21 Correct 149 ms 6532 KB Output is correct
22 Correct 145 ms 6556 KB Output is correct
23 Correct 422 ms 268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 154 ms 6724 KB Output is correct
3 Correct 151 ms 6484 KB Output is correct
4 Correct 1580 ms 63516 KB Output is correct
5 Correct 154 ms 6516 KB Output is correct
6 Correct 156 ms 6528 KB Output is correct
7 Correct 165 ms 6540 KB Output is correct
8 Correct 158 ms 6640 KB Output is correct
9 Correct 152 ms 6468 KB Output is correct
10 Correct 145 ms 6504 KB Output is correct
11 Correct 155 ms 8012 KB Output is correct
12 Correct 150 ms 8032 KB Output is correct
13 Correct 155 ms 8008 KB Output is correct
14 Correct 1653 ms 63088 KB Output is correct
15 Correct 152 ms 8092 KB Output is correct
16 Correct 1510 ms 63224 KB Output is correct
17 Correct 1505 ms 63196 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 16 ms 840 KB Output is correct
3 Correct 25 ms 832 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 0 ms 204 KB Output is correct
7 Correct 1 ms 256 KB Output is correct
8 Correct 2 ms 204 KB Output is correct
9 Correct 1 ms 284 KB Output is correct
10 Correct 1 ms 296 KB Output is correct
11 Correct 1 ms 288 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 204 KB Output is correct
14 Correct 0 ms 204 KB Output is correct
15 Correct 1 ms 288 KB Output is correct
16 Correct 15 ms 1232 KB Output is correct
17 Correct 179 ms 10168 KB Output is correct
18 Correct 1 ms 204 KB Output is correct
19 Correct 1 ms 204 KB Output is correct
20 Correct 0 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 0 ms 204 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 2 ms 332 KB Output is correct
27 Correct 2 ms 332 KB Output is correct
28 Correct 930 ms 25496 KB Output is correct
29 Correct 0 ms 204 KB Output is correct
30 Correct 1553 ms 62832 KB Output is correct
31 Correct 1568 ms 62948 KB Output is correct
32 Correct 1682 ms 62992 KB Output is correct
33 Correct 0 ms 204 KB Output is correct
34 Correct 1599 ms 62864 KB Output is correct
35 Correct 1618 ms 62892 KB Output is correct
36 Correct 1670 ms 62844 KB Output is correct
37 Correct 1743 ms 62824 KB Output is correct
38 Correct 0 ms 204 KB Output is correct
39 Correct 142 ms 6500 KB Output is correct
40 Correct 151 ms 6436 KB Output is correct
41 Correct 150 ms 6468 KB Output is correct
42 Correct 149 ms 6488 KB Output is correct
43 Correct 143 ms 6508 KB Output is correct
44 Correct 169 ms 6508 KB Output is correct
45 Correct 142 ms 6480 KB Output is correct
46 Correct 150 ms 6448 KB Output is correct
47 Correct 151 ms 6564 KB Output is correct
48 Correct 153 ms 6444 KB Output is correct
49 Correct 153 ms 6600 KB Output is correct
50 Correct 152 ms 6600 KB Output is correct
51 Correct 1516 ms 62896 KB Output is correct
52 Correct 1578 ms 62920 KB Output is correct
53 Correct 1645 ms 62920 KB Output is correct
54 Correct 149 ms 6532 KB Output is correct
55 Correct 145 ms 6556 KB Output is correct
56 Correct 422 ms 268 KB Output is correct
57 Correct 0 ms 204 KB Output is correct
58 Correct 154 ms 6724 KB Output is correct
59 Correct 151 ms 6484 KB Output is correct
60 Correct 1580 ms 63516 KB Output is correct
61 Correct 154 ms 6516 KB Output is correct
62 Correct 156 ms 6528 KB Output is correct
63 Correct 165 ms 6540 KB Output is correct
64 Correct 158 ms 6640 KB Output is correct
65 Correct 152 ms 6468 KB Output is correct
66 Correct 145 ms 6504 KB Output is correct
67 Correct 155 ms 8012 KB Output is correct
68 Correct 150 ms 8032 KB Output is correct
69 Correct 155 ms 8008 KB Output is correct
70 Correct 1653 ms 63088 KB Output is correct
71 Correct 152 ms 8092 KB Output is correct
72 Correct 1510 ms 63224 KB Output is correct
73 Correct 1505 ms 63196 KB Output is correct
74 Correct 1 ms 204 KB Output is correct
75 Correct 1 ms 204 KB Output is correct
76 Correct 0 ms 204 KB Output is correct
77 Correct 1 ms 204 KB Output is correct
78 Correct 0 ms 204 KB Output is correct
79 Correct 15 ms 1220 KB Output is correct
80 Correct 1632 ms 100144 KB Output is correct
81 Correct 1645 ms 100184 KB Output is correct
82 Correct 1725 ms 100208 KB Output is correct
83 Correct 1703 ms 100288 KB Output is correct
84 Correct 1718 ms 100192 KB Output is correct
85 Correct 1612 ms 100236 KB Output is correct
86 Correct 413 ms 12824 KB Output is correct
87 Correct 0 ms 204 KB Output is correct