제출 #537341

#제출 시각아이디문제언어결과실행 시간메모리
537341DJ035이상한 기계 (APIO19_strange_device)C++17
100 / 100
547 ms69856 KiB
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,avx,avx2")
#include <bits/stdc++.h>
#define MEM 1111111
#define sanic ios_base::sync_with_stdio(0)
#define x first
#define y second
#define pf push_front
#define pb push_back
#define all(v) v.begin(), v.end()
#define sz size()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pi;
const ll INF = 1e17+7;
const ll MOD = 998244353;
ll gcd(ll a, ll b){
    if(a%b) return gcd(b, a%b);
    return b;
}
ll t,n,m,a,b;
ll l[MEM], r[MEM];
signed main(){
    sanic; cin.tie(0);
    cin >> n >> a >> b;
    for(int i=0; i<n; i++)
        cin >> l[i] >> r[i];
    if((ll)(1e18)/a<b){
        ll ret=0;
        for(int i=0; i<n; i++) ret += r[i]-l[i]+1;
        cout << ret;
        return 0;
    }
    t = (a/gcd(a,b+1))*b;
    for(int i=0; i<n; i++) {
        if(r[i]-l[i]+1>=t){
            cout << t;
            return 0;
        }
    }
    vector<pi> v;
    for(int i=0; i<n; i++){
        if(l[i]%t<=r[i]%t) v.pb({l[i]%t,r[i]%t});
        else{
            v.pb({l[i]%t,t-1});
            v.pb({0,r[i]%t});
        }
    }
    sort(all(v));
    ll mn=v[0].x, mx=v[0].y;
    ll ans=0;
    for(int i=1; i<v.sz; i++){
        if(mx<v[i].x){
            ans += mx-mn+1;
            mn = v[i].x;
            mx = v[i].y;
        }
        mx = max(v[i].y,mx);
    }
    ans += mx-mn+1;
    cout << ans;
}

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

strange_device.cpp: In function 'int main()':
strange_device.cpp:54:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   54 |     for(int i=1; i<v.sz; i++){
      |                   ^
#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...