답안 #708301

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
708301 2023-03-11T14:05:31 Z 600Mihnea 이상한 기계 (APIO19_strange_device) C++17
100 / 100
883 ms 115928 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

pair<int, int> get(int t, int a, int b)
{
	int x = (t + t / b) % a;
	int y = t % b;
	return { x, y };
}

bool same_dumb(int t1, int t2, int a, int b)
{
	return get(t1, a, b) == get(t2, a, b);
}

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

const int lim = 20;

void print(vector<int> v)
{
	cout << " ---> ";
	for (auto& x : v)
	{
		cout << x << " ";
	}
	cout << "\n";
}

void solve()
{ 
	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);
}

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

	solve();
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 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 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1108 KB Output is correct
17 Correct 62 ms 8084 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 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 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 261 ms 16764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 604 ms 78588 KB Output is correct
3 Correct 633 ms 80328 KB Output is correct
4 Correct 769 ms 93096 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 604 ms 78588 KB Output is correct
3 Correct 633 ms 80328 KB Output is correct
4 Correct 769 ms 93096 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 709 ms 93196 KB Output is correct
7 Correct 705 ms 93188 KB Output is correct
8 Correct 648 ms 93088 KB Output is correct
9 Correct 744 ms 93204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 604 ms 78588 KB Output is correct
3 Correct 633 ms 80328 KB Output is correct
4 Correct 769 ms 93096 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 62 ms 11792 KB Output is correct
7 Correct 61 ms 11824 KB Output is correct
8 Correct 58 ms 11852 KB Output is correct
9 Correct 63 ms 11852 KB Output is correct
10 Correct 59 ms 11808 KB Output is correct
11 Correct 55 ms 11860 KB Output is correct
12 Correct 56 ms 11864 KB Output is correct
13 Correct 63 ms 11908 KB Output is correct
14 Correct 56 ms 11764 KB Output is correct
15 Correct 70 ms 11980 KB Output is correct
16 Correct 67 ms 11844 KB Output is correct
17 Correct 60 ms 11756 KB Output is correct
18 Correct 616 ms 93232 KB Output is correct
19 Correct 660 ms 93172 KB Output is correct
20 Correct 684 ms 93132 KB Output is correct
21 Correct 70 ms 11784 KB Output is correct
22 Correct 58 ms 11788 KB Output is correct
23 Correct 118 ms 15180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 68 ms 11860 KB Output is correct
3 Correct 66 ms 11832 KB Output is correct
4 Correct 643 ms 80340 KB Output is correct
5 Correct 65 ms 11864 KB Output is correct
6 Correct 67 ms 11764 KB Output is correct
7 Correct 66 ms 11832 KB Output is correct
8 Correct 64 ms 11760 KB Output is correct
9 Correct 69 ms 11832 KB Output is correct
10 Correct 62 ms 11772 KB Output is correct
11 Correct 64 ms 11836 KB Output is correct
12 Correct 61 ms 11740 KB Output is correct
13 Correct 65 ms 11860 KB Output is correct
14 Correct 738 ms 80320 KB Output is correct
15 Correct 59 ms 11804 KB Output is correct
16 Correct 634 ms 93280 KB Output is correct
17 Correct 619 ms 93224 KB Output is correct
18 Correct 1 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 6 ms 1108 KB Output is correct
3 Correct 5 ms 1108 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 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 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 0 ms 212 KB Output is correct
11 Correct 1 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 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 5 ms 1108 KB Output is correct
17 Correct 62 ms 8084 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Correct 1 ms 212 KB Output is correct
21 Correct 1 ms 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 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 261 ms 16764 KB Output is correct
29 Correct 0 ms 212 KB Output is correct
30 Correct 604 ms 78588 KB Output is correct
31 Correct 633 ms 80328 KB Output is correct
32 Correct 769 ms 93096 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 709 ms 93196 KB Output is correct
35 Correct 705 ms 93188 KB Output is correct
36 Correct 648 ms 93088 KB Output is correct
37 Correct 744 ms 93204 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 62 ms 11792 KB Output is correct
40 Correct 61 ms 11824 KB Output is correct
41 Correct 58 ms 11852 KB Output is correct
42 Correct 63 ms 11852 KB Output is correct
43 Correct 59 ms 11808 KB Output is correct
44 Correct 55 ms 11860 KB Output is correct
45 Correct 56 ms 11864 KB Output is correct
46 Correct 63 ms 11908 KB Output is correct
47 Correct 56 ms 11764 KB Output is correct
48 Correct 70 ms 11980 KB Output is correct
49 Correct 67 ms 11844 KB Output is correct
50 Correct 60 ms 11756 KB Output is correct
51 Correct 616 ms 93232 KB Output is correct
52 Correct 660 ms 93172 KB Output is correct
53 Correct 684 ms 93132 KB Output is correct
54 Correct 70 ms 11784 KB Output is correct
55 Correct 58 ms 11788 KB Output is correct
56 Correct 118 ms 15180 KB Output is correct
57 Correct 0 ms 212 KB Output is correct
58 Correct 68 ms 11860 KB Output is correct
59 Correct 66 ms 11832 KB Output is correct
60 Correct 643 ms 80340 KB Output is correct
61 Correct 65 ms 11864 KB Output is correct
62 Correct 67 ms 11764 KB Output is correct
63 Correct 66 ms 11832 KB Output is correct
64 Correct 64 ms 11760 KB Output is correct
65 Correct 69 ms 11832 KB Output is correct
66 Correct 62 ms 11772 KB Output is correct
67 Correct 64 ms 11836 KB Output is correct
68 Correct 61 ms 11740 KB Output is correct
69 Correct 65 ms 11860 KB Output is correct
70 Correct 738 ms 80320 KB Output is correct
71 Correct 59 ms 11804 KB Output is correct
72 Correct 634 ms 93280 KB Output is correct
73 Correct 619 ms 93224 KB Output is correct
74 Correct 1 ms 324 KB Output is correct
75 Correct 1 ms 320 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 1 ms 212 KB Output is correct
79 Correct 7 ms 1480 KB Output is correct
80 Correct 747 ms 115896 KB Output is correct
81 Correct 749 ms 115816 KB Output is correct
82 Correct 812 ms 115732 KB Output is correct
83 Correct 860 ms 115796 KB Output is correct
84 Correct 883 ms 115680 KB Output is correct
85 Correct 740 ms 115928 KB Output is correct
86 Correct 119 ms 18164 KB Output is correct
87 Correct 0 ms 212 KB Output is correct