Submission #202081

# Submission time Handle Problem Language Result Execution time Memory
202081 2020-02-13T15:14:33 Z red1108 Strange Device (APIO19_strange_device) C++17
45 / 100
608 ms 35824 KB
#include<bits/stdc++.h>
#include<ext/rope>
using namespace std;
using namespace __gnu_cxx;
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false);cin.tie(0)
#define fopen freopen("input.txt", "r", stdin)
#define eb emplace_back
#define em emplace
#define prec(a) cout<<fixed;cout.precision(a);
#define all(a) (a).begin(), (a).end()
typedef long long ll;typedef long double ld;typedef unsigned long long ul;typedef unsigned int ui;typedef pair<int,int> pii;typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tiii;
const ll INF = 2e18;
const int inf = 2e9;
template<class T>
void pr(T t) {cerr << t << " ";}
template<class T, class ...Args>
void pr(T a, Args ...args) {cerr << a << " ";pr(args...);}
template<class ...Args>
void prl(Args ...args) {pr(args...);cerr << endl;}

int n;
ll A, B, m, ans;
double tmp;
bool flag;
vector<pll> h;
int main(){
	fastio;
	cin>>n>>A>>B;
	tmp = (double)A*B;
	ll g = __gcd(A,B+1);
	if((double)A/g>(double)1e18/B) m = 2e18;
	else m = A*B/g;
	for(int i=1;i<=n;i++){
		ll a, b;
		cin>>a>>b;
		if(b-a+1>=m){
			flag=true;
			continue;
		}
		a%=m;b%=m;
		if(a<=b) h.eb(a,b);
		else{
			h.eb(a,m-1);h.eb(0,b);
		}
	}
	if(flag){
		cout<<m;return 0;
	}
	sort(all(h));
	ll ma=-1;
	for(auto i:h){
		ans = ans + max(i.fi-ma-1, 0LL);
		ma = max(ma, i.se);
	}
	ans = ans + m-1-ma;
	cout<<m-ans;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 10 ms 764 KB Output is correct
3 Correct 10 ms 760 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 10 ms 1144 KB Output is correct
17 Correct 63 ms 5732 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 394 ms 31424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 524 ms 16852 KB Output is correct
3 Correct 524 ms 16940 KB Output is correct
4 Correct 519 ms 35736 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 524 ms 16852 KB Output is correct
3 Correct 524 ms 16940 KB Output is correct
4 Correct 519 ms 35736 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 543 ms 35796 KB Output is correct
7 Correct 554 ms 35672 KB Output is correct
8 Execution timed out 33 ms 3564 KB Time limit exceeded (wall clock)
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 524 ms 16852 KB Output is correct
3 Correct 524 ms 16940 KB Output is correct
4 Correct 519 ms 35736 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 69 ms 5740 KB Output is correct
7 Correct 60 ms 5736 KB Output is correct
8 Correct 56 ms 5816 KB Output is correct
9 Correct 61 ms 5736 KB Output is correct
10 Correct 59 ms 5736 KB Output is correct
11 Correct 58 ms 5736 KB Output is correct
12 Correct 60 ms 5736 KB Output is correct
13 Correct 58 ms 5740 KB Output is correct
14 Correct 57 ms 5868 KB Output is correct
15 Correct 62 ms 5736 KB Output is correct
16 Correct 61 ms 5740 KB Output is correct
17 Correct 60 ms 5884 KB Output is correct
18 Correct 538 ms 35668 KB Output is correct
19 Correct 531 ms 35824 KB Output is correct
20 Execution timed out 300 ms 35680 KB Time limit exceeded (wall clock)
21 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 60 ms 2548 KB Output is correct
3 Correct 59 ms 2560 KB Output is correct
4 Correct 608 ms 16852 KB Output is correct
5 Correct 57 ms 2540 KB Output is correct
6 Correct 58 ms 2544 KB Output is correct
7 Correct 58 ms 2544 KB Output is correct
8 Correct 60 ms 2540 KB Output is correct
9 Correct 57 ms 2540 KB Output is correct
10 Correct 61 ms 2544 KB Output is correct
11 Correct 58 ms 2540 KB Output is correct
12 Correct 56 ms 2556 KB Output is correct
13 Correct 58 ms 2544 KB Output is correct
14 Correct 561 ms 16852 KB Output is correct
15 Correct 59 ms 2544 KB Output is correct
16 Correct 546 ms 27480 KB Output is correct
17 Correct 543 ms 27476 KB Output is correct
18 Correct 5 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 10 ms 764 KB Output is correct
3 Correct 10 ms 760 KB Output is correct
4 Correct 4 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 376 KB Output is correct
11 Correct 5 ms 504 KB Output is correct
12 Correct 5 ms 376 KB Output is correct
13 Correct 5 ms 376 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 376 KB Output is correct
16 Correct 10 ms 1144 KB Output is correct
17 Correct 63 ms 5732 KB Output is correct
18 Correct 5 ms 504 KB Output is correct
19 Correct 5 ms 376 KB Output is correct
20 Correct 5 ms 376 KB Output is correct
21 Correct 5 ms 376 KB Output is correct
22 Correct 5 ms 376 KB Output is correct
23 Correct 5 ms 376 KB Output is correct
24 Correct 5 ms 376 KB Output is correct
25 Correct 5 ms 376 KB Output is correct
26 Correct 5 ms 376 KB Output is correct
27 Correct 5 ms 376 KB Output is correct
28 Correct 394 ms 31424 KB Output is correct
29 Correct 5 ms 376 KB Output is correct
30 Correct 524 ms 16852 KB Output is correct
31 Correct 524 ms 16940 KB Output is correct
32 Correct 519 ms 35736 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 543 ms 35796 KB Output is correct
35 Correct 554 ms 35672 KB Output is correct
36 Execution timed out 33 ms 3564 KB Time limit exceeded (wall clock)
37 Halted 0 ms 0 KB -