답안 #393917

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
393917 2021-04-24T21:54:58 Z ritul_kr_singh 이상한 기계 (APIO19_strange_device) C++17
5 / 100
545 ms 16752 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define sp << ' ' <<
#define nl << '\n'

const int INF = 1e18;

bool comp(array<int, 2> &x, array<int, 2> &y){
	return x[1] < y[1];
}

signed main(){
	cin.tie(0)->sync_with_stdio(0);

	int n, A, B, l, r; cin >> n >> A >> B;

	int g = A / __gcd(A, B + 1LL);

	if(g > (INF + 5LL) / B) g = INF + 5;
	else g *= B;

	vector<array<int, 2>> q;
	bool all = false;

	while(n--){
		cin >> l >> r;
		int lm = l % g, rm = r % g;
		// if(l + (g - lm) <= r) q.push_back({lm, g-1}), q.push_back({0, rm});
		// else q.push_back({lm, rm});
		all = all or (r - l + 1LL >= g);
		if(lm <= rm) q.push_back({lm, rm});
		else q.push_back({lm, g-1LL}), q.push_back({0, rm});
	}

	int res = 0;
	l = -1, r = -2;
	sort(q.begin(), q.end(), comp);

	for(auto &i : q){
		if(r < i[0]){
			res += r - l + 1LL;
			l = i[0], r = i[1];
		}else r = i[1], l = min(l, i[0]);
	}

	res += r - l + 1LL;

	if(all) res = g;

	cout << res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 7 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 1 ms 332 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 545 ms 16752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 545 ms 16752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 545 ms 16752 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 56 ms 2480 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 7 ms 592 KB Output isn't correct
3 Halted 0 ms 0 KB -