Submission #132358

# Submission time Handle Problem Language Result Execution time Memory
132358 2019-07-18T18:22:05 Z bogdan10bos Strange Device (APIO19_strange_device) C++14
0 / 100
3 ms 380 KB
/// Just for others, not for me :( 9 days and counting
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
typedef pair<LL, LL> pii;

LL A, B;

int main()
{
	freopen("1.in", "r", stdin);

	int T;
	cin >> T >> A >> B;

	LL d = __gcd(A, B + 1);
	LL K = A / d;
	K *= B;

	vector<pii> itvs;
	for(int i = 1; i <= T; i++)
	{
		LL st, dr;
		cin >> st >> dr;
		if(dr - st + 1 >= K)
		{
			cout << K << '\n';
			exit(0);
		}
		st %= K, dr %= K;
		if(st <= dr)
			itvs.push_back({st, dr});
		else
		{
			itvs.push_back({st, K - 1});
			itvs.push_back({0, dr});
		}
	}

	sort(itvs.begin(), itvs.end(),
		[](pii a, pii b)
		{
			if(a.second == b.second)	return a.first < b.first;
			return a.second < b.second;
		});

	LL ans = 0;
	while(!itvs.empty())
	{
		pii itv = itvs.back();
		itvs.pop_back();
		while(!itvs.empty())
		{
			if(itvs.back().second >= itv.first)
			{
				pii itv2 = itvs.back();
				itvs.pop_back();
				itv.first = min(itv.first, itv2.first);
			}
			else
				break;
		}

		ans += itv.second - itv.first + 1;
	}

	cout << ans << '\n';
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
  freopen("1.in", "r", stdin);
  ~~~~~~~^~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 380 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 256 KB Output isn't correct
2 Halted 0 ms 0 KB -