Submission #202080

#TimeUsernameProblemLanguageResultExecution timeMemory
202080red1108이상한 기계 (APIO19_strange_device)C++17
5 / 100
603 ms35796 KiB
#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;
	if(tmp>1e18) m = 2e18;
	else m = A*B;
	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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...