Submission #316832

# Submission time Handle Problem Language Result Execution time Memory
316832 2020-10-28T09:35:29 Z sofapuden Strange Device (APIO19_strange_device) C++14
10 / 100
651 ms 25348 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	ll n, a, b; cin >> n >> a >> b;
	ll ans = 0;
	if(LONG_LONG_MAX/b <= a){
		for(int i = 0; i < n; ++i){
			ll l, r; cin >> l >> r;
			ans+=r-l+1ll;
		}
		cout << ans << "\n";
		return 0;	
	}
	vector<array<ll,3>> inter;
	for(int i = 0; i < n; ++i){
		ll l, r; cin >> l >> r;
		if(r-l+1 >= a*b){
			cout << a*b << "\n";
			return 0;
		}
		if(l%(a*b) > r%(a*b)){
			inter.push_back({0,l%(a*b),r%(a*b)});
		}
		else{
			inter.push_back({1,l%(a*b),r%(a*b)});
		}
	}
	sort(inter.begin(),inter.end());
	ll hi = -1;
	for(int i = 0; i < n; ++i){
		if(inter[i][0] && !inter[0][0] && inter[i][1] >= inter[0][1])break;
		if(inter[i][0] && inter[i][1] > hi+1){
			ans += inter[i][1] - hi -1;
		}
		hi = max(hi,inter[i][2]);
	}
	if(inter[0][0] == 1){
		ans+=a*b-hi-1;
	}
	else{
		ans+=max(0ll,inter[0][1]-hi-1);
	}
		
	cout << a*b - ans << "\n";
}
	
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 6 ms 832 KB Output is correct
3 Correct 6 ms 832 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 436 ms 25048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 586 ms 25348 KB Output is correct
3 Incorrect 584 ms 25160 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 586 ms 25348 KB Output is correct
3 Incorrect 584 ms 25160 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 586 ms 25348 KB Output is correct
3 Incorrect 584 ms 25160 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 59 ms 3596 KB Output is correct
3 Correct 59 ms 3564 KB Output is correct
4 Correct 651 ms 25288 KB Output is correct
5 Correct 57 ms 3564 KB Output is correct
6 Correct 57 ms 3564 KB Output is correct
7 Correct 60 ms 3564 KB Output is correct
8 Correct 59 ms 3564 KB Output is correct
9 Correct 58 ms 3572 KB Output is correct
10 Correct 59 ms 3564 KB Output is correct
11 Correct 58 ms 3564 KB Output is correct
12 Correct 51 ms 3688 KB Output is correct
13 Correct 58 ms 3568 KB Output is correct
14 Correct 641 ms 25216 KB Output is correct
15 Incorrect 60 ms 3572 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 6 ms 832 KB Output is correct
3 Correct 6 ms 832 KB Output is correct
4 Incorrect 1 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -