// Comment
//
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
using ll = long long;
using pi = pair<int, int>;
const int INF = 0x3f3f3f3f;
const ll LINF = 1ll * INF * INF;
using pli = pair<ll, ll>;
using ti = tuple<ll, ll, int>;
ll gcd(ll a, ll b) {
if(b == 0) return a;
return gcd(b, a%b);
}
int N; ll A, B, G;
vector<ti> Lines;
struct PT {
ll x, y; // 0 <= x <= A/G, 0 <= y < B
PT(ll _x, ll _y): x(_x), y(_y) {}
PT up() {
ll _x = x, _y = y;
_y++;
if(y == B) {
_x++;
_y = 0;
}
return PT(_x, _y);
}
};
vector<ll> getNums(ll t) {
// t = (xA + n (A/G) + m) B + z;
ll a = t / B, z = t % B;
ll x = a / A, y = a % A;
ll n = y / (A/G), m = y % (A/G);
ll nums[4] = {x, n, m, z};
return vector<ll>(nums, nums+4);
}
int main() {
cin >> N >> A >> B;
G = gcd(A, B+1);
for(int i=1; i<=N; i++) {
ll x, y; scanf("%lld%lld", &x, &y);
vector<ll> xs = getNums(x);
vector<ll> ys = getNums(y);
ll xabg = xs[0]*G + xs[1];
ll yabg = ys[0]*G + ys[1];
if(xabg+2 <= yabg) {
printf("%lld\n", (A/G) * B);
return 0;
}
Lines.emplace_back(xs[2], xs[3], +1);
PT pt = PT(ys[2], ys[3]).up();
Lines.emplace_back(pt.x, pt.y, -1);
if(xabg != yabg) {
Lines.emplace_back(0, 0, +1);
Lines.emplace_back(A/G, 0, -1);
}
}
Lines.emplace_back(A/G, 0, 0);
sort(ALL(Lines));
ll ans = 0; int now = 0;
for(int i=0; i+1<SZ(Lines); i++) {
ll x, y; int v; tie(x, y, v) = Lines[i];
ll nx, ny; int nv; tie(nx, ny, nv) = Lines[i+1];
now += v;
if(now >= 1) {
ans += (nx - x) * B + (ny - y);
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message
strange_device.cpp: In function 'int main()':
strange_device.cpp:58:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
58 | ll x, y; scanf("%lld%lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
9 ms |
1532 KB |
Output is correct |
3 |
Correct |
9 ms |
1532 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
8 ms |
1532 KB |
Output is correct |
17 |
Correct |
97 ms |
9316 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
256 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Correct |
0 ms |
256 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
372 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
679 ms |
49708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
368 KB |
Output is correct |
2 |
Correct |
906 ms |
49836 KB |
Output is correct |
3 |
Correct |
939 ms |
49788 KB |
Output is correct |
4 |
Correct |
859 ms |
84472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
368 KB |
Output is correct |
2 |
Correct |
906 ms |
49836 KB |
Output is correct |
3 |
Correct |
939 ms |
49788 KB |
Output is correct |
4 |
Correct |
859 ms |
84472 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
806 ms |
84472 KB |
Output is correct |
7 |
Correct |
847 ms |
84624 KB |
Output is correct |
8 |
Correct |
881 ms |
84728 KB |
Output is correct |
9 |
Correct |
1031 ms |
84476 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
368 KB |
Output is correct |
2 |
Correct |
906 ms |
49836 KB |
Output is correct |
3 |
Correct |
939 ms |
49788 KB |
Output is correct |
4 |
Correct |
859 ms |
84472 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
78 ms |
9312 KB |
Output is correct |
7 |
Correct |
89 ms |
9316 KB |
Output is correct |
8 |
Correct |
78 ms |
9316 KB |
Output is correct |
9 |
Correct |
89 ms |
9312 KB |
Output is correct |
10 |
Correct |
86 ms |
9320 KB |
Output is correct |
11 |
Correct |
84 ms |
9320 KB |
Output is correct |
12 |
Correct |
89 ms |
9428 KB |
Output is correct |
13 |
Correct |
91 ms |
9312 KB |
Output is correct |
14 |
Correct |
82 ms |
9316 KB |
Output is correct |
15 |
Correct |
93 ms |
9320 KB |
Output is correct |
16 |
Correct |
101 ms |
9356 KB |
Output is correct |
17 |
Correct |
79 ms |
9320 KB |
Output is correct |
18 |
Correct |
855 ms |
84472 KB |
Output is correct |
19 |
Correct |
853 ms |
84600 KB |
Output is correct |
20 |
Correct |
1045 ms |
84452 KB |
Output is correct |
21 |
Correct |
97 ms |
9320 KB |
Output is correct |
22 |
Correct |
78 ms |
9312 KB |
Output is correct |
23 |
Correct |
283 ms |
34888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
94 ms |
9320 KB |
Output is correct |
3 |
Correct |
94 ms |
9312 KB |
Output is correct |
4 |
Correct |
1059 ms |
49964 KB |
Output is correct |
5 |
Correct |
93 ms |
9316 KB |
Output is correct |
6 |
Correct |
96 ms |
9320 KB |
Output is correct |
7 |
Correct |
93 ms |
9316 KB |
Output is correct |
8 |
Correct |
97 ms |
9316 KB |
Output is correct |
9 |
Correct |
97 ms |
9316 KB |
Output is correct |
10 |
Correct |
106 ms |
9316 KB |
Output is correct |
11 |
Correct |
94 ms |
9580 KB |
Output is correct |
12 |
Correct |
85 ms |
9336 KB |
Output is correct |
13 |
Correct |
100 ms |
9316 KB |
Output is correct |
14 |
Correct |
1042 ms |
49836 KB |
Output is correct |
15 |
Correct |
100 ms |
9316 KB |
Output is correct |
16 |
Correct |
875 ms |
84536 KB |
Output is correct |
17 |
Correct |
863 ms |
84452 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
256 KB |
Output is correct |
2 |
Correct |
9 ms |
1532 KB |
Output is correct |
3 |
Correct |
9 ms |
1532 KB |
Output is correct |
4 |
Correct |
0 ms |
384 KB |
Output is correct |
5 |
Correct |
0 ms |
256 KB |
Output is correct |
6 |
Correct |
1 ms |
256 KB |
Output is correct |
7 |
Correct |
1 ms |
256 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 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 |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
256 KB |
Output is correct |
14 |
Correct |
1 ms |
256 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
8 ms |
1532 KB |
Output is correct |
17 |
Correct |
97 ms |
9316 KB |
Output is correct |
18 |
Correct |
1 ms |
256 KB |
Output is correct |
19 |
Correct |
0 ms |
256 KB |
Output is correct |
20 |
Correct |
1 ms |
256 KB |
Output is correct |
21 |
Correct |
0 ms |
256 KB |
Output is correct |
22 |
Correct |
1 ms |
384 KB |
Output is correct |
23 |
Correct |
1 ms |
256 KB |
Output is correct |
24 |
Correct |
1 ms |
372 KB |
Output is correct |
25 |
Correct |
2 ms |
384 KB |
Output is correct |
26 |
Correct |
2 ms |
384 KB |
Output is correct |
27 |
Correct |
1 ms |
384 KB |
Output is correct |
28 |
Correct |
679 ms |
49708 KB |
Output is correct |
29 |
Correct |
1 ms |
368 KB |
Output is correct |
30 |
Correct |
906 ms |
49836 KB |
Output is correct |
31 |
Correct |
939 ms |
49788 KB |
Output is correct |
32 |
Correct |
859 ms |
84472 KB |
Output is correct |
33 |
Correct |
0 ms |
256 KB |
Output is correct |
34 |
Correct |
806 ms |
84472 KB |
Output is correct |
35 |
Correct |
847 ms |
84624 KB |
Output is correct |
36 |
Correct |
881 ms |
84728 KB |
Output is correct |
37 |
Correct |
1031 ms |
84476 KB |
Output is correct |
38 |
Correct |
0 ms |
256 KB |
Output is correct |
39 |
Correct |
78 ms |
9312 KB |
Output is correct |
40 |
Correct |
89 ms |
9316 KB |
Output is correct |
41 |
Correct |
78 ms |
9316 KB |
Output is correct |
42 |
Correct |
89 ms |
9312 KB |
Output is correct |
43 |
Correct |
86 ms |
9320 KB |
Output is correct |
44 |
Correct |
84 ms |
9320 KB |
Output is correct |
45 |
Correct |
89 ms |
9428 KB |
Output is correct |
46 |
Correct |
91 ms |
9312 KB |
Output is correct |
47 |
Correct |
82 ms |
9316 KB |
Output is correct |
48 |
Correct |
93 ms |
9320 KB |
Output is correct |
49 |
Correct |
101 ms |
9356 KB |
Output is correct |
50 |
Correct |
79 ms |
9320 KB |
Output is correct |
51 |
Correct |
855 ms |
84472 KB |
Output is correct |
52 |
Correct |
853 ms |
84600 KB |
Output is correct |
53 |
Correct |
1045 ms |
84452 KB |
Output is correct |
54 |
Correct |
97 ms |
9320 KB |
Output is correct |
55 |
Correct |
78 ms |
9312 KB |
Output is correct |
56 |
Correct |
283 ms |
34888 KB |
Output is correct |
57 |
Correct |
1 ms |
256 KB |
Output is correct |
58 |
Correct |
94 ms |
9320 KB |
Output is correct |
59 |
Correct |
94 ms |
9312 KB |
Output is correct |
60 |
Correct |
1059 ms |
49964 KB |
Output is correct |
61 |
Correct |
93 ms |
9316 KB |
Output is correct |
62 |
Correct |
96 ms |
9320 KB |
Output is correct |
63 |
Correct |
93 ms |
9316 KB |
Output is correct |
64 |
Correct |
97 ms |
9316 KB |
Output is correct |
65 |
Correct |
97 ms |
9316 KB |
Output is correct |
66 |
Correct |
106 ms |
9316 KB |
Output is correct |
67 |
Correct |
94 ms |
9580 KB |
Output is correct |
68 |
Correct |
85 ms |
9336 KB |
Output is correct |
69 |
Correct |
100 ms |
9316 KB |
Output is correct |
70 |
Correct |
1042 ms |
49836 KB |
Output is correct |
71 |
Correct |
100 ms |
9316 KB |
Output is correct |
72 |
Correct |
875 ms |
84536 KB |
Output is correct |
73 |
Correct |
863 ms |
84452 KB |
Output is correct |
74 |
Correct |
1 ms |
256 KB |
Output is correct |
75 |
Correct |
1 ms |
384 KB |
Output is correct |
76 |
Correct |
0 ms |
256 KB |
Output is correct |
77 |
Correct |
1 ms |
256 KB |
Output is correct |
78 |
Correct |
1 ms |
256 KB |
Output is correct |
79 |
Correct |
8 ms |
1532 KB |
Output is correct |
80 |
Correct |
1076 ms |
84828 KB |
Output is correct |
81 |
Correct |
1063 ms |
84768 KB |
Output is correct |
82 |
Correct |
990 ms |
84432 KB |
Output is correct |
83 |
Correct |
1010 ms |
84608 KB |
Output is correct |
84 |
Correct |
995 ms |
84676 KB |
Output is correct |
85 |
Correct |
1002 ms |
84560 KB |
Output is correct |
86 |
Correct |
301 ms |
34888 KB |
Output is correct |
87 |
Correct |
1 ms |
384 KB |
Output is correct |