답안 #264776

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
264776 2020-08-14T09:25:30 Z dimash241 이상한 기계 (APIO19_strange_device) C++17
100 / 100
580 ms 53476 KB
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
//#pragma GCC target("avx,avx2")
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")

//# include <x86intrin.h>
# include <bits/stdc++.h>

# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;
 
template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define _USE_MATH_DEFINES_
#define ll long long
#define ld long double
#define Accepted 0
#define pb push_back
#define mp make_pair
#define sz(x) (int)(x.size())
#define every(x) x.begin(),x.end()
#define F first
#define S second
#define lb lower_bound
#define ub upper_bound
#define For(i,x,y)  for (ll i = x; i <= y; i ++) 
#define FOr(i,x,y)  for (ll i = x; i >= y; i --)
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
// ROAD to...                                                                                                                                                                                                                Red

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
	// cin.exceptions(cin.failbit); 
	// throws exception when do smth illegal
	// ex. try to read letter into int
	if (sz(s)) { setIn(s+".in"), setOut(s+".out"); } // for USACO
}

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 6e5 + 123;                                          
const int M = 22;
const int pri = 997;
const int Magic = 2101;

const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
 
int rnd (int l, int r) {
	return uniform_int_distribution<int> (l, r)(gen);
}
int n;
ll a, b;
vector < pair <ll, ll > > p;
int main () {
	SpeedForce;
	cin >> n >> a >> b;
	p.resize(n);
	for (auto &e : p) cin >> e.first >> e.second;
	
	a = a / __gcd(a,b+1);
	
	if (INF / a < b) {
		ll ans = 0;
		for (auto e : p) ans += e.second - e.first + 1;
		cout << ans << '\n';
		exit(0);
	}
	a *= b;
	vector < pair<ll, ll> > e;
	for (auto it : p) {
		if((ll)(it.first / a) + 1 < (ll)it.second / a) {
			cout << a << '\n';
			exit(0);
		}
		if (it.second/a == it.first/a) e.pb({it.first%a, it.second%a});
		else {
			e.pb({it.first % a, a-1});
			e.pb({0, it.second % a});
		}
	}
	sort(every(e));
	ll ans = 0;
	for (int i = 0; i < sz(e); ++i) {
		ll l, r;
		tie(l,r) = e[i];
		int j = i;
		while(j + 1 < sz(e) && e[j+1].first <= r) {
			++j;
			r = max(r, e[j].second);
		}
		ans += r - l + 1;
		i = j;
	}
	cout << ans << '\n';
	
	return Accepted;
}

// B...a

Compilation message

strange_device.cpp: In function 'void setIn(std::string)':
strange_device.cpp:34:31: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   34 | void setIn(string s) { freopen(s.c_str(),"r",stdin); }
      |                        ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
strange_device.cpp: In function 'void setOut(std::string)':
strange_device.cpp:35:32: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   35 | void setOut(string s) { freopen(s.c_str(),"w",stdout); }
      |                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 7 ms 1280 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 416 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1280 KB Output is correct
17 Correct 54 ms 7792 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 369 ms 41188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 500 ms 33932 KB Output is correct
3 Correct 461 ms 34016 KB Output is correct
4 Correct 445 ms 34660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 500 ms 33932 KB Output is correct
3 Correct 461 ms 34016 KB Output is correct
4 Correct 445 ms 34660 KB Output is correct
5 Correct 1 ms 288 KB Output is correct
6 Correct 459 ms 34532 KB Output is correct
7 Correct 462 ms 34656 KB Output is correct
8 Correct 473 ms 34584 KB Output is correct
9 Correct 506 ms 34660 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 500 ms 33932 KB Output is correct
3 Correct 461 ms 34016 KB Output is correct
4 Correct 445 ms 34660 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 50 ms 7832 KB Output is correct
7 Correct 50 ms 7920 KB Output is correct
8 Correct 47 ms 7792 KB Output is correct
9 Correct 54 ms 7792 KB Output is correct
10 Correct 48 ms 7796 KB Output is correct
11 Correct 50 ms 7836 KB Output is correct
12 Correct 52 ms 7920 KB Output is correct
13 Correct 50 ms 7792 KB Output is correct
14 Correct 57 ms 7792 KB Output is correct
15 Correct 52 ms 7792 KB Output is correct
16 Correct 51 ms 7792 KB Output is correct
17 Correct 48 ms 7792 KB Output is correct
18 Correct 482 ms 37856 KB Output is correct
19 Correct 458 ms 34528 KB Output is correct
20 Correct 545 ms 34588 KB Output is correct
21 Correct 50 ms 7792 KB Output is correct
22 Correct 44 ms 7792 KB Output is correct
23 Correct 150 ms 26600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 50 ms 7828 KB Output is correct
3 Correct 50 ms 7792 KB Output is correct
4 Correct 543 ms 37728 KB Output is correct
5 Correct 49 ms 7792 KB Output is correct
6 Correct 49 ms 7792 KB Output is correct
7 Correct 50 ms 7792 KB Output is correct
8 Correct 51 ms 7832 KB Output is correct
9 Correct 49 ms 7792 KB Output is correct
10 Correct 49 ms 7792 KB Output is correct
11 Correct 49 ms 7792 KB Output is correct
12 Correct 45 ms 7792 KB Output is correct
13 Correct 49 ms 7792 KB Output is correct
14 Correct 497 ms 37732 KB Output is correct
15 Correct 49 ms 7792 KB Output is correct
16 Correct 472 ms 35808 KB Output is correct
17 Correct 468 ms 53476 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 5 ms 1280 KB Output is correct
3 Correct 7 ms 1280 KB Output is correct
4 Correct 1 ms 384 KB Output is correct
5 Correct 0 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 316 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 416 KB Output is correct
12 Correct 0 ms 384 KB Output is correct
13 Correct 1 ms 384 KB Output is correct
14 Correct 0 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 5 ms 1280 KB Output is correct
17 Correct 54 ms 7792 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
19 Correct 1 ms 384 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 1 ms 384 KB Output is correct
22 Correct 0 ms 384 KB Output is correct
23 Correct 0 ms 384 KB Output is correct
24 Correct 0 ms 384 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 1 ms 384 KB Output is correct
28 Correct 369 ms 41188 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 500 ms 33932 KB Output is correct
31 Correct 461 ms 34016 KB Output is correct
32 Correct 445 ms 34660 KB Output is correct
33 Correct 1 ms 288 KB Output is correct
34 Correct 459 ms 34532 KB Output is correct
35 Correct 462 ms 34656 KB Output is correct
36 Correct 473 ms 34584 KB Output is correct
37 Correct 506 ms 34660 KB Output is correct
38 Correct 0 ms 384 KB Output is correct
39 Correct 50 ms 7832 KB Output is correct
40 Correct 50 ms 7920 KB Output is correct
41 Correct 47 ms 7792 KB Output is correct
42 Correct 54 ms 7792 KB Output is correct
43 Correct 48 ms 7796 KB Output is correct
44 Correct 50 ms 7836 KB Output is correct
45 Correct 52 ms 7920 KB Output is correct
46 Correct 50 ms 7792 KB Output is correct
47 Correct 57 ms 7792 KB Output is correct
48 Correct 52 ms 7792 KB Output is correct
49 Correct 51 ms 7792 KB Output is correct
50 Correct 48 ms 7792 KB Output is correct
51 Correct 482 ms 37856 KB Output is correct
52 Correct 458 ms 34528 KB Output is correct
53 Correct 545 ms 34588 KB Output is correct
54 Correct 50 ms 7792 KB Output is correct
55 Correct 44 ms 7792 KB Output is correct
56 Correct 150 ms 26600 KB Output is correct
57 Correct 1 ms 384 KB Output is correct
58 Correct 50 ms 7828 KB Output is correct
59 Correct 50 ms 7792 KB Output is correct
60 Correct 543 ms 37728 KB Output is correct
61 Correct 49 ms 7792 KB Output is correct
62 Correct 49 ms 7792 KB Output is correct
63 Correct 50 ms 7792 KB Output is correct
64 Correct 51 ms 7832 KB Output is correct
65 Correct 49 ms 7792 KB Output is correct
66 Correct 49 ms 7792 KB Output is correct
67 Correct 49 ms 7792 KB Output is correct
68 Correct 45 ms 7792 KB Output is correct
69 Correct 49 ms 7792 KB Output is correct
70 Correct 497 ms 37732 KB Output is correct
71 Correct 49 ms 7792 KB Output is correct
72 Correct 472 ms 35808 KB Output is correct
73 Correct 468 ms 53476 KB Output is correct
74 Correct 1 ms 384 KB Output is correct
75 Correct 0 ms 384 KB Output is correct
76 Correct 1 ms 384 KB Output is correct
77 Correct 1 ms 384 KB Output is correct
78 Correct 1 ms 288 KB Output is correct
79 Correct 5 ms 1280 KB Output is correct
80 Correct 580 ms 41572 KB Output is correct
81 Correct 547 ms 38116 KB Output is correct
82 Correct 506 ms 40652 KB Output is correct
83 Correct 535 ms 44516 KB Output is correct
84 Correct 523 ms 43364 KB Output is correct
85 Correct 496 ms 42084 KB Output is correct
86 Correct 146 ms 26600 KB Output is correct
87 Correct 1 ms 384 KB Output is correct