답안 #708303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
708303 2023-03-11T14:06:31 Z 600Mihnea 이상한 기계 (APIO19_strange_device) C++17
100 / 100
732 ms 79040 KB
#include <cmath>
#include <functional>
#include <fstream>
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
#include <list>
#include <time.h>
#include <math.h>
#include <random>
#include <deque>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
#include <cassert>
#include <bitset>
#include <sstream>
#include <chrono>
#include <cstring>
#include <numeric>
#include <cstdint>
#include <limits>
#include <numeric>
#include <iostream>


using namespace std;

#define int long long

int gcd(int a, int b)
{
	if (b == 0) return a;
	return gcd(b, a % b);
}

signed main() 
{

#ifdef ONPC	
	FILE* stream;
	freopen_s(&stream, "input.txt", "r", stdin);
#else
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#endif

	int n, mod;
	cin >> n;
	{
		int a, b;
		cin >> a >> b;
		a /= gcd(a, b + 1);
		if (a <= ((int)1e18 + 7) / b)
		{
			a *= b;
			mod = a;
		}
		else
		{
			mod = ((int)1e18 + 7);
		}
	}
	map<int, int> mars;
	auto add = [&](int l, int r)
	{
		if (l > r) return;

		mars[l]++;
		mars[r + 1]--;
	};
	vector<pair<int, int>> segs(n);
	for (auto& it : segs)
	{
		cin >> it.first >> it.second;
		if (it.second - it.first + 1 >= mod)
		{
			cout << mod << "\n";
			exit(0);
		}
		int l = it.first % mod, r = it.second % mod;
		if (l <= r)
		{
			add(l, r);
		}
		else
		{
			add(l, mod - 1);
			add(0, r);
		}
	}
	int sol = 0, cur = 0, last;
	for (auto& it : mars)
	{
		if (cur)
		{
			sol += it.first - last;
		}
		last = it.first;
		cur += it.second;
	}
	cout << sol << "\n";
	exit(0);

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 6 ms 1116 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 1108 KB Output is correct
17 Correct 58 ms 8140 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 247 ms 16216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 574 ms 78580 KB Output is correct
3 Correct 624 ms 78956 KB Output is correct
4 Correct 647 ms 78912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 574 ms 78580 KB Output is correct
3 Correct 624 ms 78956 KB Output is correct
4 Correct 647 ms 78912 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 611 ms 78920 KB Output is correct
7 Correct 610 ms 78916 KB Output is correct
8 Correct 608 ms 78920 KB Output is correct
9 Correct 711 ms 78924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 574 ms 78580 KB Output is correct
3 Correct 624 ms 78956 KB Output is correct
4 Correct 647 ms 78912 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 52 ms 8400 KB Output is correct
7 Correct 54 ms 8300 KB Output is correct
8 Correct 58 ms 8496 KB Output is correct
9 Correct 62 ms 8280 KB Output is correct
10 Correct 54 ms 8384 KB Output is correct
11 Correct 55 ms 8348 KB Output is correct
12 Correct 53 ms 8328 KB Output is correct
13 Correct 60 ms 8380 KB Output is correct
14 Correct 53 ms 8392 KB Output is correct
15 Correct 63 ms 8396 KB Output is correct
16 Correct 64 ms 8276 KB Output is correct
17 Correct 59 ms 8424 KB Output is correct
18 Correct 609 ms 79040 KB Output is correct
19 Correct 645 ms 78848 KB Output is correct
20 Correct 658 ms 78940 KB Output is correct
21 Correct 55 ms 8268 KB Output is correct
22 Correct 58 ms 8284 KB Output is correct
23 Correct 107 ms 6220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 65 ms 8512 KB Output is correct
3 Correct 62 ms 8440 KB Output is correct
4 Correct 659 ms 78860 KB Output is correct
5 Correct 64 ms 8464 KB Output is correct
6 Correct 62 ms 8468 KB Output is correct
7 Correct 61 ms 8388 KB Output is correct
8 Correct 60 ms 8508 KB Output is correct
9 Correct 63 ms 8488 KB Output is correct
10 Correct 59 ms 8472 KB Output is correct
11 Correct 63 ms 8608 KB Output is correct
12 Correct 57 ms 8492 KB Output is correct
13 Correct 65 ms 8652 KB Output is correct
14 Correct 732 ms 78828 KB Output is correct
15 Correct 54 ms 8532 KB Output is correct
16 Correct 584 ms 78924 KB Output is correct
17 Correct 587 ms 78884 KB Output is correct
18 Correct 0 ms 320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 1108 KB Output is correct
3 Correct 6 ms 1116 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 0 ms 212 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 0 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 5 ms 1108 KB Output is correct
17 Correct 58 ms 8140 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 0 ms 212 KB Output is correct
21 Correct 1 ms 324 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 247 ms 16216 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 574 ms 78580 KB Output is correct
31 Correct 624 ms 78956 KB Output is correct
32 Correct 647 ms 78912 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 611 ms 78920 KB Output is correct
35 Correct 610 ms 78916 KB Output is correct
36 Correct 608 ms 78920 KB Output is correct
37 Correct 711 ms 78924 KB Output is correct
38 Correct 1 ms 212 KB Output is correct
39 Correct 52 ms 8400 KB Output is correct
40 Correct 54 ms 8300 KB Output is correct
41 Correct 58 ms 8496 KB Output is correct
42 Correct 62 ms 8280 KB Output is correct
43 Correct 54 ms 8384 KB Output is correct
44 Correct 55 ms 8348 KB Output is correct
45 Correct 53 ms 8328 KB Output is correct
46 Correct 60 ms 8380 KB Output is correct
47 Correct 53 ms 8392 KB Output is correct
48 Correct 63 ms 8396 KB Output is correct
49 Correct 64 ms 8276 KB Output is correct
50 Correct 59 ms 8424 KB Output is correct
51 Correct 609 ms 79040 KB Output is correct
52 Correct 645 ms 78848 KB Output is correct
53 Correct 658 ms 78940 KB Output is correct
54 Correct 55 ms 8268 KB Output is correct
55 Correct 58 ms 8284 KB Output is correct
56 Correct 107 ms 6220 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 65 ms 8512 KB Output is correct
59 Correct 62 ms 8440 KB Output is correct
60 Correct 659 ms 78860 KB Output is correct
61 Correct 64 ms 8464 KB Output is correct
62 Correct 62 ms 8468 KB Output is correct
63 Correct 61 ms 8388 KB Output is correct
64 Correct 60 ms 8508 KB Output is correct
65 Correct 63 ms 8488 KB Output is correct
66 Correct 59 ms 8472 KB Output is correct
67 Correct 63 ms 8608 KB Output is correct
68 Correct 57 ms 8492 KB Output is correct
69 Correct 65 ms 8652 KB Output is correct
70 Correct 732 ms 78828 KB Output is correct
71 Correct 54 ms 8532 KB Output is correct
72 Correct 584 ms 78924 KB Output is correct
73 Correct 587 ms 78884 KB Output is correct
74 Correct 0 ms 320 KB Output is correct
75 Correct 1 ms 320 KB Output is correct
76 Correct 1 ms 316 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 0 ms 212 KB Output is correct
79 Correct 6 ms 1356 KB Output is correct
80 Correct 659 ms 78540 KB Output is correct
81 Correct 642 ms 78660 KB Output is correct
82 Correct 672 ms 78612 KB Output is correct
83 Correct 677 ms 78616 KB Output is correct
84 Correct 687 ms 78532 KB Output is correct
85 Correct 645 ms 78504 KB Output is correct
86 Correct 108 ms 5628 KB Output is correct
87 Correct 1 ms 212 KB Output is correct