Submission #316828

# Submission time Handle Problem Language Result Execution time Memory
316828 2020-10-28T09:27:04 Z sofapuden Strange Device (APIO19_strange_device) C++14
10 / 100
639 ms 25248 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((r/(a*b))-(l/(a*b)) >= 1){
			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 864 KB Output is correct
4 Incorrect 0 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 512 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 423 ms 25032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 579 ms 25032 KB Output is correct
3 Incorrect 569 ms 25164 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 579 ms 25032 KB Output is correct
3 Incorrect 569 ms 25164 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 579 ms 25032 KB Output is correct
3 Incorrect 569 ms 25164 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 60 ms 3564 KB Output is correct
3 Correct 60 ms 3588 KB Output is correct
4 Correct 639 ms 25156 KB Output is correct
5 Correct 63 ms 3564 KB Output is correct
6 Correct 57 ms 3564 KB Output is correct
7 Correct 58 ms 3564 KB Output is correct
8 Correct 60 ms 3564 KB Output is correct
9 Correct 57 ms 3564 KB Output is correct
10 Correct 58 ms 3692 KB Output is correct
11 Correct 60 ms 3564 KB Output is correct
12 Correct 50 ms 3572 KB Output is correct
13 Correct 59 ms 3564 KB Output is correct
14 Correct 626 ms 25248 KB Output is correct
15 Incorrect 61 ms 3564 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 864 KB Output is correct
4 Incorrect 0 ms 384 KB Output isn't correct
5 Halted 0 ms 0 KB -