Submission #372470

# Submission time Handle Problem Language Result Execution time Memory
372470 2021-02-28T09:41:38 Z hivakarami Strange Device (APIO19_strange_device) C++14
5 / 100
464 ms 27928 KB
#include<bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
typedef long double ld;
#define f first
#define s second
 
const int N = 1e6 + 100;
const ll mod = 1e9 + 7;
const ll inf = 1e18 + 10;

vector<pair<ll, ll>> v;

int main()
{
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	int n;
	ll a, b;
	cin >> n >> a >> b;
	ll k = a / __gcd(a, b+1);
	if(k > inf/b)
		k = inf;
	else
		k *= b;
	
	while(n--)
	{
		ll l, r;
		cin >> l >> r;
		
		if(r - l + 1 >= k)
		{
			cout << k << endl;
			return 0;
		}
		
		l = l%k;
		r = r%k;
		
		if(l <= r)
		{
			v.push_back({l, r});
		}
		else
		{
			v.push_back({l, k-1});
			v.push_back({0, r});
		}
		
	}
	
	sort(v.begin(), v.end());
	
	ll ans = 0, mx = -1;
	
	for(int i = 0; i < v.size(); i++)
	{
		ll l = v[i].f, r = v[i].s;
		if(l > mx)
			ans += r - l + 1;
		else if(r >= mx)
			ans = r - mx;
		mx = max(mx, r);	
	}
	
	cout << ans << endl;
	
    return 0;
}


 

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:59:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |  for(int i = 0; i < v.size(); i++)
      |                 ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 5 ms 1132 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 464 ms 27928 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 464 ms 27928 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Incorrect 464 ms 27928 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 49 ms 5732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 364 KB Output is correct
2 Incorrect 5 ms 1132 KB Output isn't correct
3 Halted 0 ms 0 KB -