Submission #1196940

#TimeUsernameProblemLanguageResultExecution timeMemory
1196940haitax511이상한 기계 (APIO19_strange_device)C++20
100 / 100
339 ms32720 KiB
// #include<bits/allocator.h> // #pragma GCC optimize("Ofast,unroll-loops") // #ifdef ONLINE_JUDGE // #pragma GCC target("avx2,fma,bmi,bmi2,popcnt,lzcnt,tune=native") // #endif #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace __gnu_pbds; // VVI #define fast \ ios_base::sync_with_stdio(0); \ cin.tie(0); #define ll long long #define SZ(a) (ll)a.size() #define UNIQUE(a) (a).erase(unique(all(a)), (a).end()) #define mp make_pair #define mem(a, b) memset(a, b, sizeof(a)) #define all(x) x.begin(), x.end() //Printings & debugging #define nn '\n' #define Setpre(n) cout << fixed << setprecision(n) #define deb(x) cout << #x << "=" << x << endl #define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl #define debug printf("I am here\n") // CONSTANTS #define md 10000007 #define PI acos(-1) const long double EPS = 1e-9; const ll N = 2e5 + 10; const ll M = 1e9 + 7; /// INLINE FUNCTIONS inline ll GCD(ll a, ll b) { return b == 0 ? a : GCD(b, a % b); } inline ll LCM(ll a, ll b) { return a * b / GCD(a, b); } inline long double logb(ll base, ll num) { return ( long double )log(num) / ( long double )log(base); } /// Data structures typedef unsigned long long ull; typedef pair<ll, ll> pll; typedef vector<ll> vl; typedef vector<pll> vpll; typedef vector<vl> vvl; template <typename T> using PQ = priority_queue<T>; template <typename T> using QP = priority_queue<T, vector<T>, greater<T>>; template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T> using ordered_multiset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T, typename R> using ordered_map = tree<T, R, less<T>, rb_tree_tag, tree_order_statistics_node_update>; template <typename T, typename R> using ordered_multimap = tree<T, R, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; namespace io{ template<typename First, typename Second> ostream& operator << ( ostream &os, const pair<First, Second> &p ) { return os << p.first << " " << p.second; } template<typename First, typename Second> ostream& operator << ( ostream &os, const map<First, Second> &mp ) { for( auto it : mp ) { os << it << endl; } return os; } template<typename First> ostream& operator << ( ostream &os, const vector<First> &v ) { bool space = false; for( First x : v ) { if( space ) os << " "; space = true; os << x; } return os; } template<typename First> ostream& operator << ( ostream &os, const set<First> &st ) { bool space = false; for( First x : st ) { if( space ) os << " "; space = true; os << x; } return os; } template<typename First> ostream& operator << ( ostream &os, const multiset<First> &st ) { bool space = false; for( First x : st ) { if( space ) os << " "; space = true; os << x; } return os; } template<typename First, typename Second> istream& operator >> ( istream &is, pair<First, Second> &p ) { return is >> p.first >> p.second; } template<typename First> istream& operator >> ( istream &is, vector<First> &v ) { for( First &x : v ) { is >> x; } return is; } long long fastread(){ char c; long long d = 1, x = 0; do c = getchar(); while( c == ' ' || c == '\n' ); if( c == '-' ) c = getchar(), d = -1; while( isdigit( c ) ){ x = x * 10 + c - '0'; c = getchar(); } return d * x; } static bool sep = false; using std::to_string; string to_string( bool x ){ return ( x ? "true" : "false" ); } string to_string( const string & s ){ return "\"" + s + "\""; } string to_string( const char * s ){ return "\"" + string( s ) + "\""; } string to_string ( const char & c ) { string s; s += c; return "\'" + s + "\'"; } template<typename Type> string to_string( vector<Type> ); template<typename First, typename Second> string to_string( pair<First, Second> ); template<typename Collection> string to_string( Collection ); template<typename First, typename Second> string to_string( pair<First, Second> p ){ return "{" + to_string( p.first ) + ", " + to_string( p.second ) + "}"; } template<typename Type> string to_string( vector<Type> v ) { bool sep = false; string s = "["; for( Type x: v ){ if( sep ) s += ", "; sep = true; s += to_string( x ); } s += "]"; return s; } template<typename Collection> string to_string( Collection collection ) { bool sep = false; string s = "{"; for( auto x: collection ){ if( sep ) s += ", "; sep = true; s += to_string( x ); } s += "}"; return s; } void print() { cerr << endl; sep = false; } template <typename First, typename... Other> void print( First first, Other... other ) { if( sep ) cerr << " | "; sep = true; cerr << to_string( first ); print( other... ); } } using namespace io; const ll INF=1e15+500; // ll mul(ll x) {return x==0 ? 1 : mul(x-1)*10;} const ll MAXN=3e5+100; const ll MOD=1e9+7; #define p(i,n) for(ll i=0; i<n; i++) #define rp(i,n) for(ll i=n-1; i>=0; i--) #define grid_ll vector<vector<ll>> #define grid_char vector<vector<char>> void ADD(ll& c,ll a, ll b, ll m) {c = ((a % m) + (b % m)) % m;return;} void MUL(ll& c,ll a, ll b, ll m) {c = ((a % m) * (b % m)) % m;} void SUB(ll& c,ll a, ll b, ll m) {c = ((a % m) - (b % m) + m) % m;} void MIN(ll& a, ll b) {a = min(a, b);} void MAX(ll& a, ll b) {a = max(a, b);} ll gcdExtended(ll a, ll b, ll *x, ll *y); ll modInverse(ll b, ll m){ll x,y;ll g = gcdExtended(b, m, &x, &y);if (g != 1)return -1;return (x%m + m) % m;} ll modDivide(ll a, ll b, ll m){a = a % m;ll inv = modInverse(b, m);return (inv * a) % m;} ll gcdExtended(ll a, ll b, ll *x, ll *y){if (a == 0){*x = 0, *y = 1;return b;}ll x1, y1;ll gcd = gcdExtended(b%a, a, &x1, &y1);*x = y1 - (b/a) * x1;*y = x1;return gcd;} #define f first #define s second signed main(){ fast ll n; cin>>n; ll A,B; cin>>A>>B; vector<pll> v(n); for(ll i=0;i<n; i++) cin>>v[i].f>>v[i].s; ll flag=1; ll x=(A)/__gcd(A,B+1); ll mn=2e18; vector<pll> vals; for(ll i=0; i<n; i++){ if ((v[i].s-v[i].f+1)/x>=B){ flag=0; } else{ if( v[i].s/x>=B) {v[i].s%=x*B;} if (v[i].f/x>=B) { v[i].f%=x*B; } if( v[i].f>v[i].s) {vals.push_back(mp(v[i].f,x*B-1LL)); vals.push_back(mp(0LL,v[i].s)); } else{ vals.push_back(v[i]); } } } if (flag==0) {cout<<x*B<<nn; return 0; } sort(all(vals)); ll covered=-1; ll ans=0; for(ll i=0; i<vals.size(); i++){ if( vals[i].s>covered) {ans+=vals[i].s-max(covered,vals[i].f-1); covered=vals[i].s; } } cout<<ans<<nn; }
#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...