Submission #977086

# Submission time Handle Problem Language Result Execution time Memory
977086 2024-05-07T11:19:08 Z dubabuba Strange Device (APIO19_strange_device) C++14
10 / 100
1141 ms 63360 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
typedef pair<int, int> pii;
#define ff first
#define ss second
#define MP make_pair
 
int gcd(int a, int b) {
	if(a == 0) return b;
	if(b == 0) return a;
	return gcd(b % a, a);
}
 
signed main() {
	int a, b, n, t;
	cin >> n >> a >> b;
	int d = gcd(a, b + 1);

	double sda = 1.0  * a / d * b;
	if(sda <= 1e18) t = a / d * b;
	else t = 1e18;
	set<pii> v;
 
	int l, r; bool gay = false;
	for(int i = 0; i < n; i++) {
		cin >> l >> r;
		if(r - l + 1 >= t) {
			gay = 1;
			continue;
		}
 
		l %= t;
		r %= t;
 
		if(l <= r) {
			// root->upt(l, r);
			v.insert(MP(l, r));
		}
		else {
			// root->upt(l, t - 1);
			// root->upt(0, r);
			v.insert(MP(l, t - 1));
			v.insert(MP(0, r));
		}
	}
 
	if(gay) {
		cout << t << endl;
		// if(t == (int) 1e18)
			// return 1;
		return 0;
	}

	v.insert(MP(2e18, 2e18));
 
	int ans = 0;
	l = 0, r = 0;
	for(pii p : v) {
		if(r < p.ff) {
			ans += (r - l + 1);
			l = p.ff;
			r = p.ss;
		}
		r = max(r, p.ss);
	}

	if(ans < 0) return 1;
	cout << ans << endl;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 11 ms 860 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Incorrect 0 ms 348 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 2 ms 348 KB Output is correct
5 Correct 682 ms 428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1114 ms 62952 KB Output is correct
3 Correct 1126 ms 63028 KB Output is correct
4 Correct 1131 ms 63204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1114 ms 62952 KB Output is correct
3 Correct 1126 ms 63028 KB Output is correct
4 Correct 1131 ms 63204 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1111 ms 63092 KB Output is correct
7 Correct 1121 ms 62896 KB Output is correct
8 Correct 1108 ms 63056 KB Output is correct
9 Incorrect 1141 ms 63360 KB Output isn't correct
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1114 ms 62952 KB Output is correct
3 Correct 1126 ms 63028 KB Output is correct
4 Correct 1131 ms 63204 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 107 ms 6608 KB Output is correct
7 Correct 107 ms 6484 KB Output is correct
8 Correct 106 ms 6580 KB Output is correct
9 Correct 113 ms 6512 KB Output is correct
10 Correct 107 ms 6464 KB Output is correct
11 Correct 107 ms 6480 KB Output is correct
12 Correct 106 ms 6484 KB Output is correct
13 Incorrect 115 ms 6740 KB Output isn't correct
14 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Incorrect 112 ms 6464 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Incorrect 11 ms 860 KB Output isn't correct
3 Halted 0 ms 0 KB -