Submission #561705

# Submission time Handle Problem Language Result Execution time Memory
561705 2022-05-13T11:39:35 Z hhhhaura Strange Device (APIO19_strange_device) C++14
100 / 100
660 ms 76364 KB
#define wiwihorz
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC target("sse")
#pragma loop-opt(on)
#define rep(i, a, b) for(int i = a; i <= b; i ++)
#define rrep(i, a, b) for(int i = b; i >= a; i --)
#define all(x) x.begin(), x.end()
#define ceil(a, b) ((a + b - 1) / (b))
#define int long long int
#define lld long double
#define pii pair<int, int>
#define random mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count())
#define INF 1000000000000000001
#define MOD 1000000007
#define eps (1e-9)
using namespace std;
#ifdef wiwihorz
#define print(a...)cerr<<"Line "<<__LINE__<<":",kout("["+string(#a)+"] = ", a)
void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
void kout() { cerr << endl; }
template<class T1,class ... T2>void kout(T1 a,T2 ... e){cerr<<a<<" ",kout(e...);}
#else
#define print(...) 0
#define vprint(...) 0
#endif
#define x first
#define y second
namespace solver {
	int n, A, B;
	vector<pii> v, op;
	void init_(int _n, int _A, int _B) {
		n = _n, A = _A, B = _B;
		v.assign(n + 1, {0, 0});
		op.clear();
	}
	void solve() {
		int tp = A / __gcd(A, B + 1), k, yes = 0;
		if(tp > ceil(INF - 1, B)) k = INF;
		else k = tp * B;
		rep(i, 1, n) {
			int L = v[i].x % k;
			int R = v[i].y % k;
			if(v[i].y - v[i].x >= k) {
				cout << k << "\n";
				return;
			}
			if(L > R) {
				op.push_back({L, 1});
				op.push_back({k, -1});
				op.push_back({0, 1});
				op.push_back({R + 1, -1});
			}
			else {
				op.push_back({L, 1});
				op.push_back({R + 1, -1});
			}
		}
		sort(all(op));
		int ans = 0, cnt = 0, cur = 0;
		for(auto i : op) {
			ans += (cnt > 0 ? i.x - cur : 0);
			cnt += i.y;
			cur = i.x;
		}
		cout << ans << "\n";
	}
};
using namespace solver;
signed main() {
	ios::sync_with_stdio(false), cin.tie(0);
	int n, A, B;
	cin >> n >> A >> B;
	init_(n, A, B);
	rep(i, 1, n) cin >> v[i].x >> v[i].y;
	solve();
	return 0;
}

Compilation message

strange_device.cpp:5: warning: ignoring '#pragma loop ' [-Wunknown-pragmas]
    5 | #pragma loop-opt(on)
      | 
strange_device.cpp:20:13: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
      |             ^~~~
strange_device.cpp:20:20: warning: use of 'auto' in parameter declaration only available with '-fconcepts-ts'
   20 | void vprint(auto L,auto R){while(L<R)cerr<<*L<<" \n"[next(L) == R], ++L; }
      |                    ^~~~
strange_device.cpp: In function 'void solver::solve()':
strange_device.cpp:38:36: warning: unused variable 'yes' [-Wunused-variable]
   38 |   int tp = A / __gcd(A, B + 1), k, yes = 0;
      |                                    ^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1508 KB Output is correct
3 Correct 6 ms 1624 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 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 320 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 212 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1496 KB Output is correct
17 Correct 58 ms 9808 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 320 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 354 ms 50208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 522 ms 60640 KB Output is correct
3 Correct 534 ms 63100 KB Output is correct
4 Correct 496 ms 68996 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 522 ms 60640 KB Output is correct
3 Correct 534 ms 63100 KB Output is correct
4 Correct 496 ms 68996 KB Output is correct
5 Correct 1 ms 320 KB Output is correct
6 Correct 508 ms 69012 KB Output is correct
7 Correct 493 ms 68932 KB Output is correct
8 Correct 518 ms 68888 KB Output is correct
9 Correct 598 ms 68788 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 522 ms 60640 KB Output is correct
3 Correct 534 ms 63100 KB Output is correct
4 Correct 496 ms 68996 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 50 ms 9800 KB Output is correct
7 Correct 51 ms 9800 KB Output is correct
8 Correct 54 ms 9792 KB Output is correct
9 Correct 52 ms 9804 KB Output is correct
10 Correct 48 ms 9804 KB Output is correct
11 Correct 50 ms 9808 KB Output is correct
12 Correct 47 ms 9788 KB Output is correct
13 Correct 52 ms 9804 KB Output is correct
14 Correct 48 ms 9808 KB Output is correct
15 Correct 57 ms 9800 KB Output is correct
16 Correct 56 ms 9792 KB Output is correct
17 Correct 50 ms 9812 KB Output is correct
18 Correct 513 ms 68592 KB Output is correct
19 Correct 499 ms 68928 KB Output is correct
20 Correct 611 ms 69080 KB Output is correct
21 Correct 55 ms 9792 KB Output is correct
22 Correct 48 ms 9792 KB Output is correct
23 Correct 141 ms 34760 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 54 ms 9800 KB Output is correct
3 Correct 53 ms 9800 KB Output is correct
4 Correct 625 ms 63192 KB Output is correct
5 Correct 62 ms 9792 KB Output is correct
6 Correct 56 ms 9804 KB Output is correct
7 Correct 54 ms 9800 KB Output is correct
8 Correct 56 ms 9792 KB Output is correct
9 Correct 51 ms 9792 KB Output is correct
10 Correct 55 ms 9792 KB Output is correct
11 Correct 53 ms 9800 KB Output is correct
12 Correct 51 ms 9792 KB Output is correct
13 Correct 54 ms 9808 KB Output is correct
14 Correct 604 ms 69088 KB Output is correct
15 Correct 56 ms 9784 KB Output is correct
16 Correct 507 ms 68496 KB Output is correct
17 Correct 532 ms 69240 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 6 ms 1508 KB Output is correct
3 Correct 6 ms 1624 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 212 KB Output is correct
7 Correct 1 ms 320 KB Output is correct
8 Correct 1 ms 320 KB Output is correct
9 Correct 1 ms 320 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 212 KB Output is correct
13 Correct 1 ms 324 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1496 KB Output is correct
17 Correct 58 ms 9808 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 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 1 ms 212 KB Output is correct
23 Correct 1 ms 212 KB Output is correct
24 Correct 0 ms 320 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 354 ms 50208 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 522 ms 60640 KB Output is correct
31 Correct 534 ms 63100 KB Output is correct
32 Correct 496 ms 68996 KB Output is correct
33 Correct 1 ms 320 KB Output is correct
34 Correct 508 ms 69012 KB Output is correct
35 Correct 493 ms 68932 KB Output is correct
36 Correct 518 ms 68888 KB Output is correct
37 Correct 598 ms 68788 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 50 ms 9800 KB Output is correct
40 Correct 51 ms 9800 KB Output is correct
41 Correct 54 ms 9792 KB Output is correct
42 Correct 52 ms 9804 KB Output is correct
43 Correct 48 ms 9804 KB Output is correct
44 Correct 50 ms 9808 KB Output is correct
45 Correct 47 ms 9788 KB Output is correct
46 Correct 52 ms 9804 KB Output is correct
47 Correct 48 ms 9808 KB Output is correct
48 Correct 57 ms 9800 KB Output is correct
49 Correct 56 ms 9792 KB Output is correct
50 Correct 50 ms 9812 KB Output is correct
51 Correct 513 ms 68592 KB Output is correct
52 Correct 499 ms 68928 KB Output is correct
53 Correct 611 ms 69080 KB Output is correct
54 Correct 55 ms 9792 KB Output is correct
55 Correct 48 ms 9792 KB Output is correct
56 Correct 141 ms 34760 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 54 ms 9800 KB Output is correct
59 Correct 53 ms 9800 KB Output is correct
60 Correct 625 ms 63192 KB Output is correct
61 Correct 62 ms 9792 KB Output is correct
62 Correct 56 ms 9804 KB Output is correct
63 Correct 54 ms 9800 KB Output is correct
64 Correct 56 ms 9792 KB Output is correct
65 Correct 51 ms 9792 KB Output is correct
66 Correct 55 ms 9792 KB Output is correct
67 Correct 53 ms 9800 KB Output is correct
68 Correct 51 ms 9792 KB Output is correct
69 Correct 54 ms 9808 KB Output is correct
70 Correct 604 ms 69088 KB Output is correct
71 Correct 56 ms 9784 KB Output is correct
72 Correct 507 ms 68496 KB Output is correct
73 Correct 532 ms 69240 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 212 KB Output is correct
77 Correct 1 ms 316 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 5 ms 1512 KB Output is correct
80 Correct 646 ms 76364 KB Output is correct
81 Correct 660 ms 76080 KB Output is correct
82 Correct 628 ms 75948 KB Output is correct
83 Correct 606 ms 75932 KB Output is correct
84 Correct 605 ms 75808 KB Output is correct
85 Correct 597 ms 75692 KB Output is correct
86 Correct 142 ms 34652 KB Output is correct
87 Correct 1 ms 212 KB Output is correct