Submission #320987

# Submission time Handle Problem Language Result Execution time Memory
320987 2020-11-10T12:43:31 Z Drew_ Strange Device (APIO19_strange_device) C++14
5 / 100
5000 ms 31628 KB
#include <bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define f1 first
#define s2 second

#define fastio ios :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define debug(x...) cerr << "[" << #x << "]: " << x << "\n";

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using pl = pair<ll, ll>;

ld const PI = 4*atan((ld)1);

int main()
{
	fastio;

	ll n, a, b;
	cin >> n >> a >> b;

	vector<pl> v(n);
	for (pl &x : v)
		cin >> x.f1 >> x.s2;

	ll gcd = __gcd(a, b+1);
	if (v.back().s2/a < b / gcd)
	{
		ll res = 0;
		for (pl x : v)
			res += (x.s2 - x.f1 + 1);
		cout << res << '\n';	
		return 0;
	}
	ll mod =  (a/gcd) * b;
	
	vector<pl> range; //first: duration, second: state
	for (pl x : v)
	{
		if (x.s2 - x.f1 + 1 >= mod)
		{
			cout << mod << '\n';
			return 0;
		}

		ll l = x.f1 % mod;
		ll r = x.s2 % mod;

		debug(l);
		debug(r);

		if (l <= r)
		{
			range.pb({l, 1}); 
			range.pb({r+1, -1});
		}
		else
		{
			range.pb({l, 1});
			range.pb({a*b, -1});
			range.pb({0, 1});
			range.pb({r+1, -1});
		}
	}
	sort(range.begin(), range.end());

	//for (auto x : range)
	//{
	//	cout << "-> " << x.f1 << " " << x.s2 << '\n';
	//}

	ll ctr = 0;
	ll res = 0;
	for (int i = 0; i+1 < range.size(); ++i)
	{
		ctr += range[i].s2;
		if (ctr > 0) res += (range[i+1].f1 - range[i].f1);
	}
	cout << res << '\n';
	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:78:22: 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]
   78 |  for (int i = 0; i+1 < range.size(); ++i)
      |                  ~~~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 221 ms 1900 KB Output is correct
3 Correct 218 ms 1768 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 360 KB Output is correct
2 Correct 0 ms 364 KB Output is correct
3 Correct 1 ms 364 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 1 ms 396 KB Output is correct
2 Correct 22 ms 492 KB Output is correct
3 Correct 22 ms 492 KB Output is correct
4 Correct 24 ms 492 KB Output is correct
5 Execution timed out 5073 ms 28012 KB Time limit exceeded
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Execution timed out 5092 ms 28824 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Execution timed out 5092 ms 28824 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 492 KB Output is correct
2 Execution timed out 5092 ms 28824 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 2191 ms 8940 KB Output is correct
3 Correct 2185 ms 9540 KB Output is correct
4 Execution timed out 5072 ms 31628 KB Time limit exceeded
5 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 221 ms 1900 KB Output is correct
3 Correct 218 ms 1768 KB Output is correct
4 Incorrect 1 ms 364 KB Output isn't correct
5 Halted 0 ms 0 KB -