제출 #475910

#제출 시각아이디문제언어결과실행 시간메모리
475910mat_v이상한 기계 (APIO19_strange_device)C++14
35 / 100
755 ms86164 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
#define fb(i,a,b) for(int (i) = (a); (i) >= (b); --(i))
#define mod 998244353
#define xx first
#define yy second
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define ll long long
#define pii pair<ll,ll>


using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>,rb_tree_tag, tree_order_statistics_node_update> ordered_set;/// find_by_order(x)(x+1th) , order_of_key() (strictly less)
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());


int n;
ll a,b;
ll brt;
pii niz[1000005];
vector<pii> svi;

void ddj(ll x, ll y){
    svi.pb({x,0});
    svi.pb({y,1});
}

int main()
{

    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> n >> a >> b;
    ll uk = 0;
    ff(i,1,n){
        cin >> niz[i].xx >> niz[i].yy;
        uk += (niz[i].yy - niz[i].xx);
    }
    ll tmp = __gcd(b + 1, a);
    tmp = a / tmp;
    ll sta = LLONG_MAX;
    bool flg = 0;
    if(tmp >= sta/b){
        cout << uk << "\n";
        return 0;
    }
    brt = tmp*b;
    ff(i,1,n){
        if((niz[i].yy - niz[i].xx +1) >= brt){
            cout << brt << "\n";
            return 0;
        }
        if((niz[i].yy%brt) < (niz[i].xx%brt)){
            ddj(niz[i].xx%brt, brt - 1);
            ddj(0, niz[i].yy%brt);
        }
        else ddj(niz[i].xx%brt, niz[i].yy%brt);
    }
    sort(svi.begin(), svi.end());
    int op = 0;
    ll last = -1;
    ll ans = brt;
    for(auto c:svi){

        if(c.yy == 1){
            op--;
            last = c.xx;
            continue;
        }
        else{
            if(op == 0){
                ans -= (c.xx - last);
                ans++;
            }
            last = c.xx;
            op++;
        }
    }
    ans -= (brt - last);
    ans++;
    cout << ans << "\n";



    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

strange_device.cpp: In function 'int main()':
strange_device.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
strange_device.cpp:40:5: note: in expansion of macro 'ff'
   40 |     ff(i,1,n){
      |     ^~
strange_device.cpp:6:27: warning: unnecessary parentheses in declaration of 'i' [-Wparentheses]
    6 | #define ff(i,a,b) for(int (i) = (a); (i) <= (b); ++(i))
      |                           ^
strange_device.cpp:53:5: note: in expansion of macro 'ff'
   53 |     ff(i,1,n){
      |     ^~
strange_device.cpp:47:10: warning: unused variable 'flg' [-Wunused-variable]
   47 |     bool flg = 0;
      |          ^~~
#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...