답안 #172106

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
172106 2019-12-31T06:44:35 Z super_j6 이상한 기계 (APIO19_strange_device) C++14
50 / 100
711 ms 25328 KB
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
#define endl '\n'
#define pi pair<long long, long long>

const long long inf = 200000000000000000;
const int maxn = 2000001;
long long n, m, a, b;
pi p[maxn];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	cin >> n >> a >> b;
	m = min(inf / b, a / __gcd(b % a + 1, a)) * b;
	
	for(int i = 0; i < n; i++){
		cin >> p[i].first >> p[i].second;
		if(p[i].second - p[i].first >= m) p[i] = {0, m - 1};
		p[i].first %= m, p[i].second %= m;
		if(p[i].second < p[i].first){
			p[i + 1] = {p[i].first, m - 1};
			p[i].first = 0;
			i++, n++;
		}
	} 
	
	p[n] = {m, m};
	sort(p, p + n);
	
	long long ret = 0;
	for(long long i = 0, j = p[0].second, k = p[0].first; i < n; i++){
		j = max(j, p[i].second);
		if(j < p[i + 1].first){
			ret += j - k + 1;
			k = p[i + 1].first;
		}
	}
	
	cout << ret << endl;
	
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 632 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 504 KB Output is correct
17 Correct 65 ms 1960 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 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 380 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 429 ms 16052 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 596 ms 16888 KB Output is correct
3 Correct 582 ms 17012 KB Output is correct
4 Correct 585 ms 23288 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 596 ms 16888 KB Output is correct
3 Correct 582 ms 17012 KB Output is correct
4 Correct 585 ms 23288 KB Output is correct
5 Correct 2 ms 504 KB Output is correct
6 Correct 587 ms 21228 KB Output is correct
7 Correct 590 ms 24544 KB Output is correct
8 Correct 590 ms 25196 KB Output is correct
9 Correct 641 ms 25012 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 596 ms 16888 KB Output is correct
3 Correct 582 ms 17012 KB Output is correct
4 Correct 585 ms 23288 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 59 ms 5624 KB Output is correct
7 Correct 63 ms 5752 KB Output is correct
8 Correct 60 ms 5628 KB Output is correct
9 Incorrect 62 ms 3660 KB Output isn't correct
10 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 141 ms 3320 KB Output is correct
3 Correct 63 ms 1912 KB Output is correct
4 Correct 711 ms 19464 KB Output is correct
5 Correct 63 ms 1912 KB Output is correct
6 Correct 65 ms 3152 KB Output is correct
7 Correct 64 ms 3592 KB Output is correct
8 Correct 65 ms 1912 KB Output is correct
9 Correct 63 ms 2936 KB Output is correct
10 Correct 63 ms 1912 KB Output is correct
11 Correct 63 ms 2684 KB Output is correct
12 Correct 58 ms 4044 KB Output is correct
13 Correct 64 ms 4124 KB Output is correct
14 Correct 645 ms 18300 KB Output is correct
15 Correct 63 ms 4088 KB Output is correct
16 Correct 644 ms 25236 KB Output is correct
17 Correct 579 ms 25328 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 632 KB Output is correct
3 Correct 8 ms 632 KB Output is correct
4 Correct 3 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 2 ms 376 KB Output is correct
12 Correct 2 ms 376 KB Output is correct
13 Correct 2 ms 376 KB Output is correct
14 Correct 2 ms 376 KB Output is correct
15 Correct 2 ms 376 KB Output is correct
16 Correct 7 ms 504 KB Output is correct
17 Correct 65 ms 1960 KB Output is correct
18 Correct 2 ms 376 KB Output is correct
19 Correct 2 ms 376 KB Output is correct
20 Correct 2 ms 376 KB Output is correct
21 Correct 2 ms 376 KB Output is correct
22 Correct 2 ms 380 KB Output is correct
23 Correct 2 ms 376 KB Output is correct
24 Correct 2 ms 376 KB Output is correct
25 Correct 2 ms 376 KB Output is correct
26 Correct 3 ms 376 KB Output is correct
27 Correct 3 ms 376 KB Output is correct
28 Correct 429 ms 16052 KB Output is correct
29 Correct 2 ms 376 KB Output is correct
30 Correct 596 ms 16888 KB Output is correct
31 Correct 582 ms 17012 KB Output is correct
32 Correct 585 ms 23288 KB Output is correct
33 Correct 2 ms 504 KB Output is correct
34 Correct 587 ms 21228 KB Output is correct
35 Correct 590 ms 24544 KB Output is correct
36 Correct 590 ms 25196 KB Output is correct
37 Correct 641 ms 25012 KB Output is correct
38 Correct 2 ms 376 KB Output is correct
39 Correct 59 ms 5624 KB Output is correct
40 Correct 63 ms 5752 KB Output is correct
41 Correct 60 ms 5628 KB Output is correct
42 Incorrect 62 ms 3660 KB Output isn't correct
43 Halted 0 ms 0 KB -