답안 #572362

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
572362 2022-06-04T09:47:58 Z CpDark 이상한 기계 (APIO19_strange_device) C++14
65 / 100
465 ms 32572 KB
#include <bits/stdc++.h>
#define fastInput ios::sync_with_stdio(false); cin.tie(nullptr);

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pii;
typedef vector<pii> vp;
typedef vector<bool> vb;
typedef vector<vb> vvb;

ll A, B;
inline pii getTime(ll t) {
	ll x = (t + (t / B)) % A;
	ll y = t % B;
	return { x,y };
}

inline void pushTime(pii p, ll mod, vp &points) {

	if (p.first % mod <= p.second % mod) {
		points.push_back({ p.first % mod, p.second % mod });
	}
	else {
		points.push_back({ p.first % mod, mod - 1 });
		points.push_back({ 0, p.second % mod });
	}
	
}

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


int main() {
	fastInput;
	int n;
	cin >> n >> A >> B;

	ll mod = (A / gcd(A, B + 1));
	if (mod > LLONG_MAX/B)mod = 1e18 + 7;
	else mod *= B;
	if (mod < 0)mod = 1e18 + 7;
	vp times(n);
	vp points;
	ll l, r;
	for (int i = 0; i < n; i++) {
		cin >> l >> r;
		times[i] = { l,r};
		pushTime(times[i], mod, points);
	}
	
	sort(points.begin(), points.end());
	ll count = 0;
	int open = 0;
	ll last = points[0].second;
	ll start = points[0].first;
	for (int i = 1; i < points.size(); i++) {
		if (points[i].first > last) {
			ll amount = last - start + 1;
			start = points[i].first;
			count += amount;
		}
		last = max(last, points[i].second);
		
	}
	ll amount = last - start + 1;
	count += amount;
	cout << count;

	return 0;
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:67:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |  for (int i = 1; i < points.size(); i++) {
      |                  ~~^~~~~~~~~~~~~~~
strange_device.cpp:64:6: warning: unused variable 'open' [-Wunused-variable]
   64 |  int open = 0;
      |      ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 4 ms 852 KB Output is correct
3 Correct 4 ms 860 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 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 228 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 4 ms 852 KB Output is correct
17 Correct 41 ms 4028 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 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 328 ms 32560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 395 ms 32444 KB Output is correct
3 Correct 371 ms 32428 KB Output is correct
4 Correct 366 ms 32516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 395 ms 32444 KB Output is correct
3 Correct 371 ms 32428 KB Output is correct
4 Correct 366 ms 32516 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 380 ms 32552 KB Output is correct
7 Correct 385 ms 32452 KB Output is correct
8 Correct 388 ms 32444 KB Output is correct
9 Correct 398 ms 32448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 395 ms 32444 KB Output is correct
3 Correct 371 ms 32428 KB Output is correct
4 Correct 366 ms 32516 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 43 ms 3944 KB Output is correct
7 Correct 42 ms 4012 KB Output is correct
8 Correct 36 ms 4052 KB Output is correct
9 Correct 38 ms 4040 KB Output is correct
10 Correct 36 ms 4020 KB Output is correct
11 Correct 38 ms 4004 KB Output is correct
12 Correct 36 ms 4088 KB Output is correct
13 Correct 44 ms 4048 KB Output is correct
14 Correct 37 ms 4040 KB Output is correct
15 Correct 40 ms 4072 KB Output is correct
16 Correct 40 ms 3960 KB Output is correct
17 Correct 37 ms 4048 KB Output is correct
18 Correct 383 ms 32540 KB Output is correct
19 Correct 389 ms 32456 KB Output is correct
20 Correct 418 ms 32572 KB Output is correct
21 Correct 40 ms 3968 KB Output is correct
22 Correct 35 ms 3988 KB Output is correct
23 Correct 117 ms 13972 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 41 ms 4024 KB Output is correct
3 Correct 42 ms 4060 KB Output is correct
4 Correct 465 ms 32480 KB Output is correct
5 Correct 39 ms 4008 KB Output is correct
6 Correct 41 ms 4048 KB Output is correct
7 Correct 40 ms 4036 KB Output is correct
8 Correct 41 ms 4048 KB Output is correct
9 Correct 43 ms 4008 KB Output is correct
10 Correct 41 ms 4068 KB Output is correct
11 Correct 42 ms 4084 KB Output is correct
12 Correct 36 ms 4040 KB Output is correct
13 Correct 40 ms 3964 KB Output is correct
14 Correct 406 ms 32488 KB Output is correct
15 Correct 39 ms 4016 KB Output is correct
16 Correct 397 ms 32500 KB Output is correct
17 Correct 395 ms 32472 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 4 ms 852 KB Output is correct
3 Correct 4 ms 860 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 1 ms 212 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 228 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 4 ms 852 KB Output is correct
17 Correct 41 ms 4028 KB Output is correct
18 Correct 0 ms 212 KB Output is correct
19 Correct 0 ms 212 KB Output is correct
20 Incorrect 0 ms 212 KB Output isn't correct
21 Halted 0 ms 0 KB -