Submission #316829

# Submission time Handle Problem Language Result Execution time Memory
316829 2020-10-28T09:29:02 Z sofapuden Strange Device (APIO19_strange_device) C++14
10 / 100
643 ms 25168 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= inter[0][2];
	if(inter[0][0] == 1){
		ans = inter[0][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 1 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 1 ms 384 KB Output is correct
2 Correct 0 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 1 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 420 ms 25152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 573 ms 25156 KB Output is correct
3 Incorrect 578 ms 25168 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 573 ms 25156 KB Output is correct
3 Incorrect 578 ms 25168 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 256 KB Output is correct
2 Correct 573 ms 25156 KB Output is correct
3 Incorrect 578 ms 25168 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 57 ms 3564 KB Output is correct
3 Correct 57 ms 3564 KB Output is correct
4 Correct 643 ms 25032 KB Output is correct
5 Correct 57 ms 3564 KB Output is correct
6 Correct 60 ms 3564 KB Output is correct
7 Correct 58 ms 3560 KB Output is correct
8 Correct 60 ms 3572 KB Output is correct
9 Correct 57 ms 3572 KB Output is correct
10 Correct 58 ms 3564 KB Output is correct
11 Correct 59 ms 3572 KB Output is correct
12 Correct 48 ms 3564 KB Output is correct
13 Correct 58 ms 3500 KB Output is correct
14 Correct 613 ms 25036 KB Output is correct
15 Incorrect 59 ms 3572 KB Output isn't correct
16 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 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 -