답안 #568692

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
568692 2022-05-26T05:22:47 Z Zanite 이상한 기계 (APIO19_strange_device) C++17
35 / 100
677 ms 49940 KB
// You can't change other people; you can only change yourself.

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

// Pragmas
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

// Namespaces
#define yume using
#define wo namespace
#define kanaeyo std
#define nazotte __gnu_pbds
yume wo kanaeyo;
yume wo nazotte;

// Data types
using i8	= __int128;
using ll	= long long;
using si	= short int;
using ld	= long double;

// Pairs
using pi8	= pair<i8, i8>;
using pll	= pair<ll, ll>;
using pii	= pair<int, int>;
using psi	= pair<si, si>;
using pld	= pair<ld, ld>;
#define fi first
#define se second

// PBDS
template<typename T>
using ordered_set	= tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

// Quick macro functions
#define sqr(x) ((x)*(x))
#define pow2(x) (1ll << (x))
#define debug(x) cout << #x << " = " << (x) << '\n'
#define debugV(x, a) cout << #x << "[" << (a) << "] = " << (x[a]) << '\n'

// Check min and max
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chmax(T &a, T b) {a = max(a, b);}
 
// Modular arithmetic
template<typename T> void maddto(T &a, T b, T mod) {a += b; a %= mod;}
template<typename T> void msubto(T &a, T b, T mod) {a -= b; while (a < 0) a += mod; a %= mod;}
template<typename T> void mmulto(T &a, T b, T mod) {a *= b; a %= mod;}
 
template<typename T> T madd(T a, T b, T mod) {a += b; a %= mod; return a;}
template<typename T> T msub(T a, T b, T mod) {a -= b; while (a < 0) a += mod; return a;}
template<typename T> T mmul(T a, T b, T mod) {a *= b; a %= mod; return a;}

// Constants
const ll ModA	= 998244353;
const ll ModC	= 1e9 + 7;
const ll INF	= 1e18;
const ll iINF	= 1e9;
const ld EPS	= 1e-9;
const ld iEPS	= 1e-6;

ll gcd(ll x, ll y) {
	if (!y) return x;
	return gcd(y, x % y);
}

ll n, A, B;
vector<pll> segments;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);

	scanf("%lld %lld %lld", &n, &A, &B);
	ll loop = (A * B) / gcd(A, B+1);
	for (ll l, r, i = 1; i <= n; i++) {
		scanf("%lld %lld", &l, &r);
		if (r - l + 1 >= loop) {
			printf("%lld\n", loop);
			return 0;
		} else {
			ll lx = l % loop, rx = r % loop;
			if (lx <= rx) {
				segments.push_back({lx, 1});
				segments.push_back({rx+1, -1});
			} else {
				segments.push_back({0, 1});
				segments.push_back({rx+1, -1});

				segments.push_back({lx, 1});
				segments.push_back({loop, -1});
			}
		}
	}

	sort(segments.begin(), segments.end());
	ll ans = 0, depth = 0, lastOpen = -1;
	for (auto &[pos, d] : segments) {
		if (depth == 0) {
			lastOpen = pos;
		}
		depth += d;
		if (depth == 0) {
			ans += pos - lastOpen;
		}
	}
	printf("%lld\n", ans);
}

Compilation message

strange_device.cpp: In function 'int main()':
strange_device.cpp:77:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   77 |  scanf("%lld %lld %lld", &n, &A, &B);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:80:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   80 |   scanf("%lld %lld", &l, &r);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 984 KB Output is correct
3 Correct 6 ms 856 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 0 ms 212 KB Output is correct
12 Correct 0 ms 224 KB Output is correct
13 Correct 1 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 6 ms 856 KB Output is correct
17 Correct 58 ms 4592 KB Output is correct
18 Incorrect 0 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 0 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Incorrect 0 ms 212 KB Output isn't correct
6 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 380 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 368 ms 33184 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 512 ms 33272 KB Output is correct
3 Correct 535 ms 33244 KB Output is correct
4 Correct 552 ms 40308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 512 ms 33272 KB Output is correct
3 Correct 535 ms 33244 KB Output is correct
4 Correct 552 ms 40308 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 597 ms 40708 KB Output is correct
7 Correct 580 ms 40668 KB Output is correct
8 Correct 563 ms 40180 KB Output is correct
9 Correct 627 ms 40460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 512 ms 33272 KB Output is correct
3 Correct 535 ms 33244 KB Output is correct
4 Correct 552 ms 40308 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 56 ms 7184 KB Output is correct
7 Correct 55 ms 7280 KB Output is correct
8 Correct 53 ms 7256 KB Output is correct
9 Correct 51 ms 7240 KB Output is correct
10 Correct 69 ms 7216 KB Output is correct
11 Correct 69 ms 7176 KB Output is correct
12 Correct 55 ms 7220 KB Output is correct
13 Correct 56 ms 7228 KB Output is correct
14 Correct 52 ms 7236 KB Output is correct
15 Correct 57 ms 7256 KB Output is correct
16 Correct 64 ms 7228 KB Output is correct
17 Correct 55 ms 7276 KB Output is correct
18 Correct 574 ms 41320 KB Output is correct
19 Correct 598 ms 49940 KB Output is correct
20 Correct 677 ms 45404 KB Output is correct
21 Correct 59 ms 7224 KB Output is correct
22 Correct 47 ms 7300 KB Output is correct
23 Correct 148 ms 26700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 57 ms 4572 KB Output is correct
3 Correct 57 ms 4508 KB Output is correct
4 Correct 644 ms 33224 KB Output is correct
5 Correct 72 ms 4544 KB Output is correct
6 Correct 58 ms 4580 KB Output is correct
7 Correct 53 ms 4552 KB Output is correct
8 Correct 60 ms 4540 KB Output is correct
9 Correct 52 ms 4556 KB Output is correct
10 Correct 59 ms 4556 KB Output is correct
11 Correct 61 ms 4544 KB Output is correct
12 Correct 46 ms 4508 KB Output is correct
13 Correct 57 ms 4556 KB Output is correct
14 Correct 640 ms 33280 KB Output is correct
15 Correct 57 ms 4492 KB Output is correct
16 Correct 536 ms 38072 KB Output is correct
17 Correct 554 ms 39412 KB Output is correct
18 Incorrect 1 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 5 ms 984 KB Output is correct
3 Correct 6 ms 856 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 0 ms 212 KB Output is correct
12 Correct 0 ms 224 KB Output is correct
13 Correct 1 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 6 ms 856 KB Output is correct
17 Correct 58 ms 4592 KB Output is correct
18 Incorrect 0 ms 212 KB Output isn't correct
19 Halted 0 ms 0 KB -