답안 #238384

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
238384 2020-06-11T00:01:53 Z luciocf 이상한 기계 (APIO19_strange_device) C++14
20 / 100
1026 ms 83864 KB
#include <bits/stdc++.h>

#define ff first
#define ss second

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

const int maxn = 3e6+10;
const ll inf = 1e18;

int n;
ll A, B, p;

vector<pii> event;

void add_event(ll l, ll r)
{
	if (p <= inf/B)
		l %= (p*B), r %= (p*B);

	if (l <= r)
	{
		event.push_back({l, 0});
		event.push_back({r, 1});
	}
	else
	{
		event.push_back({l, 0});
		event.push_back({p*B-1ll, 1});

		event.push_back({0, 0});
		event.push_back({r, 1});
	}
}

int main(void)
{
	scanf("%d %lld %lld", &n, &A, &B);

	ll g = __gcd(A, B+1);
	p = A/g;

	bool flag = 0;

	for (int i = 1; i <= n; i++)
	{
		ll l, r;
		scanf("%lld %lld", &l, &r);

		if ((r-l+1)/p >= B)
			flag = 1;

		if (l/B == r/B) add_event(l, r);
		else
		{
			add_event(l, (l/B + 1ll)*B - 1ll);

			if (l/B != r/B - 1ll)
				add_event((l/B + 1ll)*B, (r/B)*B - 1ll);

			add_event((r/B)*B, r);
		}
	}

	if (flag)
	{
		printf("%lld\n", p*B);
		return 0;
	}

	ll prev, ans = 0;
	int open = 0;

	sort(event.begin(), event.end());

	for (auto E: event)
	{
		ll x = E.ff, type = E.ss;

		if (open == 0) prev = x;

		if (type == 0) open++;
		else open--;

		if (open == 0) ans += (x-prev+1ll);
	}

	printf("%lld\n", ans);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:41:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %lld %lld", &n, &A, &B);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:51:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &l, &r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 11 ms 768 KB Output is correct
3 Correct 12 ms 768 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1152 KB Output is correct
17 Correct 77 ms 5732 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 4 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 4 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 6 ms 512 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 799 ms 83864 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 660 ms 16848 KB Output is correct
3 Incorrect 1026 ms 66076 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 660 ms 16848 KB Output is correct
3 Incorrect 1026 ms 66076 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 660 ms 16848 KB Output is correct
3 Incorrect 1026 ms 66076 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 256 KB Output is correct
2 Correct 74 ms 2580 KB Output is correct
3 Incorrect 66 ms 2540 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 384 KB Output is correct
2 Correct 11 ms 768 KB Output is correct
3 Correct 12 ms 768 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 4 ms 256 KB Output is correct
6 Correct 5 ms 256 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 4 ms 256 KB Output is correct
11 Correct 5 ms 384 KB Output is correct
12 Correct 5 ms 256 KB Output is correct
13 Correct 5 ms 256 KB Output is correct
14 Correct 4 ms 256 KB Output is correct
15 Correct 5 ms 384 KB Output is correct
16 Correct 11 ms 1152 KB Output is correct
17 Correct 77 ms 5732 KB Output is correct
18 Correct 4 ms 384 KB Output is correct
19 Correct 5 ms 384 KB Output is correct
20 Correct 4 ms 256 KB Output is correct
21 Correct 4 ms 256 KB Output is correct
22 Correct 4 ms 384 KB Output is correct
23 Correct 5 ms 384 KB Output is correct
24 Correct 4 ms 256 KB Output is correct
25 Correct 6 ms 512 KB Output is correct
26 Correct 5 ms 384 KB Output is correct
27 Correct 5 ms 384 KB Output is correct
28 Correct 799 ms 83864 KB Output is correct
29 Correct 4 ms 256 KB Output is correct
30 Correct 660 ms 16848 KB Output is correct
31 Incorrect 1026 ms 66076 KB Output isn't correct
32 Halted 0 ms 0 KB -