답안 #631751

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
631751 2022-08-18T16:11:18 Z TranGiaHuy1508 이상한 기계 (APIO19_strange_device) C++17
100 / 100
486 ms 53428 KB
/*
	Unknown's C++ Template (v3.2)
*/

#include "bits/stdc++.h"
using namespace std;

#define int long long

using ll = long long;
using ld = long double;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;
using vvii = vector<vii>;
template <class T> using maxpq = priority_queue<T>;
template <class T> using minpq = priority_queue<T, vector<T>, greater<T>>;

#define pb push_back
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
#define mid ((l+r)>>1)
#define fi first
#define se second

#ifdef LOCAL
	#define debug(x) cout << #x << " = " << x << "\n";
#else
	#define debug(x) ;
#endif

template <class A, class B>
ostream& operator << (ostream& out, pair<A, B> x)
{ out << "(" << x.first << ", " << x.second << ")"; return out; }

template <class T>
ostream& operator << (ostream& out, vector<T> x){
	out << "[";
	for (int i=0; i<sz(x); i++) { out << (i ? ", " : "") << x[i]; }
	out << "]"; return out;
}

template <class T>
istream& operator >> (istream& in, vector<T> &x){
	for (auto &i: x) in >> i;
	return in;
}

const ld PI = acos(-1.0);
const int allmod[3] = {(int)1e9+7, 998244353, (int)1e9+9};
const int mod = allmod[0];
const int maxn = 2e5 + 64;
const ll inf = 1e18;
const ld eps = 1e-6;
const int multitest = 0;

int mult(int a, int b){
	if ((a > 4e18 / b) || (b > 4e18 / a)) return 4e18;
	return a * b;
}

void main_program(){
	int n, A, B; cin >> n >> A >> B;
	int g = __gcd(A, B + 1);
	int m = A / g;

	int md = mult(m, B);
	vii crr;

	for (int i = 0; i < n; i++){
		int L, R; cin >> L >> R;
		// L = a * md + b
		// R = c * md + d
		int a = L / md, b = L % md, c = R / md, d = R % md;
		debug(a); debug(b); debug(c); debug(d);
		if (b <= d){
			if (a == c) crr.emplace_back(b, d);
			else{
				cout << md << "\n";
				return;
			}
		}
		else{
			if (a + 1 == c){
				crr.emplace_back(b, md - 1);
				crr.emplace_back(0, d);
			}
			else{
				cout << md << "\n";
				return;
			}
		}
	}

	sort(all(crr)); debug(crr);
	int lim = 0, res = 0;
	for (auto [i, j]: crr){
		lim = max(lim, i);
		res += max(0LL, j - lim + 1);
		lim = max(lim, j+1);
	}
	cout << res << "\n";
}

void pre_main(){

}

signed main(){
	#ifdef LOCAL
		auto stime = chrono::high_resolution_clock::now();
	#endif
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	#ifndef ONLINE_JUDGE
		if (fopen(".inp", "r")){
			freopen(".inp", "r", stdin);
			freopen(".out", "w", stdout);
		}
	#endif
	int t = 1; if (multitest) cin >> t;
	pre_main();
	while (t--) main_program();
	#ifdef LOCAL
		auto etime = chrono::high_resolution_clock::now();
		auto duration = chrono::duration_cast<chrono::milliseconds>(etime-stime).count();
		cout << "\n[" << duration << "ms]\n";
	#endif
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:117:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  117 |    freopen(".inp", "r", stdin);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~
strange_device.cpp:118:11: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  118 |    freopen(".out", "w", stdout);
      |    ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 5 ms 1056 KB Output is correct
3 Correct 5 ms 984 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 320 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 0 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 6 ms 1004 KB Output is correct
17 Correct 44 ms 5696 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 212 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 300 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 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 301 ms 41276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 453 ms 53096 KB Output is correct
3 Correct 401 ms 53340 KB Output is correct
4 Correct 384 ms 53268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 453 ms 53096 KB Output is correct
3 Correct 401 ms 53340 KB Output is correct
4 Correct 384 ms 53268 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 409 ms 53200 KB Output is correct
7 Correct 440 ms 53120 KB Output is correct
8 Correct 395 ms 53124 KB Output is correct
9 Correct 433 ms 53164 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 453 ms 53096 KB Output is correct
3 Correct 401 ms 53340 KB Output is correct
4 Correct 384 ms 53268 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 40 ms 5640 KB Output is correct
7 Correct 46 ms 5652 KB Output is correct
8 Correct 44 ms 5664 KB Output is correct
9 Correct 41 ms 5660 KB Output is correct
10 Correct 40 ms 5728 KB Output is correct
11 Correct 44 ms 5684 KB Output is correct
12 Correct 37 ms 5700 KB Output is correct
13 Correct 45 ms 5688 KB Output is correct
14 Correct 39 ms 5696 KB Output is correct
15 Correct 44 ms 5724 KB Output is correct
16 Correct 42 ms 5632 KB Output is correct
17 Correct 41 ms 5608 KB Output is correct
18 Correct 404 ms 53284 KB Output is correct
19 Correct 392 ms 53092 KB Output is correct
20 Correct 443 ms 53428 KB Output is correct
21 Correct 43 ms 5644 KB Output is correct
22 Correct 35 ms 5700 KB Output is correct
23 Correct 129 ms 18492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 56 ms 5716 KB Output is correct
3 Correct 46 ms 5700 KB Output is correct
4 Correct 473 ms 53224 KB Output is correct
5 Correct 46 ms 5664 KB Output is correct
6 Correct 49 ms 5664 KB Output is correct
7 Correct 43 ms 5716 KB Output is correct
8 Correct 43 ms 5700 KB Output is correct
9 Correct 48 ms 5660 KB Output is correct
10 Correct 41 ms 5648 KB Output is correct
11 Correct 45 ms 5652 KB Output is correct
12 Correct 38 ms 5656 KB Output is correct
13 Correct 41 ms 5644 KB Output is correct
14 Correct 452 ms 53156 KB Output is correct
15 Correct 41 ms 5660 KB Output is correct
16 Correct 398 ms 53156 KB Output is correct
17 Correct 398 ms 53244 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 5 ms 1056 KB Output is correct
3 Correct 5 ms 984 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 320 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 0 ms 212 KB Output is correct
12 Correct 1 ms 320 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 320 KB Output is correct
15 Correct 1 ms 312 KB Output is correct
16 Correct 6 ms 1004 KB Output is correct
17 Correct 44 ms 5696 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 212 KB Output is correct
22 Correct 1 ms 212 KB Output is correct
23 Correct 1 ms 300 KB Output is correct
24 Correct 1 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 301 ms 41276 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 453 ms 53096 KB Output is correct
31 Correct 401 ms 53340 KB Output is correct
32 Correct 384 ms 53268 KB Output is correct
33 Correct 1 ms 212 KB Output is correct
34 Correct 409 ms 53200 KB Output is correct
35 Correct 440 ms 53120 KB Output is correct
36 Correct 395 ms 53124 KB Output is correct
37 Correct 433 ms 53164 KB Output is correct
38 Correct 0 ms 212 KB Output is correct
39 Correct 40 ms 5640 KB Output is correct
40 Correct 46 ms 5652 KB Output is correct
41 Correct 44 ms 5664 KB Output is correct
42 Correct 41 ms 5660 KB Output is correct
43 Correct 40 ms 5728 KB Output is correct
44 Correct 44 ms 5684 KB Output is correct
45 Correct 37 ms 5700 KB Output is correct
46 Correct 45 ms 5688 KB Output is correct
47 Correct 39 ms 5696 KB Output is correct
48 Correct 44 ms 5724 KB Output is correct
49 Correct 42 ms 5632 KB Output is correct
50 Correct 41 ms 5608 KB Output is correct
51 Correct 404 ms 53284 KB Output is correct
52 Correct 392 ms 53092 KB Output is correct
53 Correct 443 ms 53428 KB Output is correct
54 Correct 43 ms 5644 KB Output is correct
55 Correct 35 ms 5700 KB Output is correct
56 Correct 129 ms 18492 KB Output is correct
57 Correct 1 ms 212 KB Output is correct
58 Correct 56 ms 5716 KB Output is correct
59 Correct 46 ms 5700 KB Output is correct
60 Correct 473 ms 53224 KB Output is correct
61 Correct 46 ms 5664 KB Output is correct
62 Correct 49 ms 5664 KB Output is correct
63 Correct 43 ms 5716 KB Output is correct
64 Correct 43 ms 5700 KB Output is correct
65 Correct 48 ms 5660 KB Output is correct
66 Correct 41 ms 5648 KB Output is correct
67 Correct 45 ms 5652 KB Output is correct
68 Correct 38 ms 5656 KB Output is correct
69 Correct 41 ms 5644 KB Output is correct
70 Correct 452 ms 53156 KB Output is correct
71 Correct 41 ms 5660 KB Output is correct
72 Correct 398 ms 53156 KB Output is correct
73 Correct 398 ms 53244 KB Output is correct
74 Correct 0 ms 212 KB Output is correct
75 Correct 1 ms 212 KB Output is correct
76 Correct 1 ms 212 KB Output is correct
77 Correct 1 ms 212 KB Output is correct
78 Correct 0 ms 316 KB Output is correct
79 Correct 4 ms 1000 KB Output is correct
80 Correct 486 ms 53136 KB Output is correct
81 Correct 467 ms 53200 KB Output is correct
82 Correct 451 ms 53220 KB Output is correct
83 Correct 474 ms 53192 KB Output is correct
84 Correct 433 ms 53176 KB Output is correct
85 Correct 445 ms 53320 KB Output is correct
86 Correct 151 ms 18424 KB Output is correct
87 Correct 1 ms 212 KB Output is correct