답안 #171731

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
171731 2019-12-30T08:33:21 Z Sensei 이상한 기계 (APIO19_strange_device) C++17
5 / 100
668 ms 16912 KB
/*
	DATE:		2019-12-30 11:10:15
	NAME:		
	PROBLEM:	APIO19_strange_device
*/
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e6;
const long long LLINF = 1e18 + 100;

class Segment {
public:
	long long l, r;
	Segment() {}
	Segment(long long x, long long y) {
		l = x;
		r = y;
	}
};

long long f(long long x, long long y) {
	if (x > LLINF / y) {
		return LLINF;
	}

	return x * y;
}

int main() {
	int n;
	cin >> n;

	long long A, B;
	cin >> A >> B;

	long long C = f(A, B);

	vector<Segment> segments;

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

		segment.l %= C;
		segment.r %= C;

		if (segment.l <= segment.r) {
			segments.push_back(segment);
		}
		else {
			segments.push_back(Segment(0, segment.r));
			segments.push_back(Segment(segment.l, C - 1));
		}
	}

	sort(segments.begin(), segments.end(), [](Segment x, Segment y) {
		if (x.l == y.l) {
			return x.r < y.r;
		}

		return x.l < y.l;
	});

	long long lastr = -1;
	long long ans = 0;

	for (int i = 0; i < segments.size(); i++) {
		if (segments[i].l > lastr) {
			lastr = segments[i].l - 1;
		}

		if (segments[i].r > lastr) {
			ans += segments[i].r - lastr;
			lastr = segments[i].r;
		}
	}

	cout << ans << "\n";

	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:69:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < segments.size(); i++) {
                  ~~^~~~~~~~~~~~~~~~~
strange_device.cpp:44:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld %lld", &segment.l, &segment.r);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 632 KB Output is correct
3 Correct 8 ms 760 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Incorrect 2 ms 296 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 435 ms 16844 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 601 ms 16912 KB Output is correct
3 Incorrect 603 ms 16840 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 601 ms 16912 KB Output is correct
3 Incorrect 603 ms 16840 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 601 ms 16912 KB Output is correct
3 Incorrect 603 ms 16840 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 256 KB Output is correct
2 Correct 64 ms 2536 KB Output is correct
3 Correct 63 ms 2516 KB Output is correct
4 Correct 666 ms 16820 KB Output is correct
5 Correct 64 ms 2512 KB Output is correct
6 Correct 63 ms 2540 KB Output is correct
7 Correct 62 ms 2524 KB Output is correct
8 Correct 66 ms 2668 KB Output is correct
9 Correct 62 ms 2508 KB Output is correct
10 Correct 64 ms 2536 KB Output is correct
11 Correct 66 ms 2536 KB Output is correct
12 Correct 55 ms 2540 KB Output is correct
13 Correct 63 ms 2504 KB Output is correct
14 Correct 668 ms 16864 KB Output is correct
15 Incorrect 66 ms 2540 KB Output isn't correct
16 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 632 KB Output is correct
3 Correct 8 ms 760 KB Output is correct
4 Incorrect 2 ms 376 KB Output isn't correct
5 Halted 0 ms 0 KB -