제출 #1135961

#제출 시각아이디문제언어결과실행 시간메모리
1135961nathan4690Strange Device (APIO19_strange_device)C++20
100 / 100
457 ms33480 KiB
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define f1(i,n) for(int i=1;i<=n;i++)
#define __file_name ""
using namespace std;
const ll maxn = 1e6+5, inf=1e18;

ll n,a,b,v,ans;
vector<pair<ll,ll>> all;

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    if(fopen(__file_name ".inp", "r")){
        freopen(__file_name ".inp","r",stdin);
        freopen(__file_name ".out","w",stdout);
    }
    // code here
    cin >> n >> a >> b;
    v = a / __gcd(a, b + 1);
    if(inf / b / v < 1) v = inf;
    else v *= b;
    f1(i,n){
        ll l, r;
        cin >> l >> r;
        if(r - l + 1 >= v){
            cout << v << '\n';
            return 0;
        }
        if(l / v != r / v){
            all.push_back({0, 1});
            all.push_back({r % v + 1, -1});
            all.push_back({l % v, 1});
            all.push_back({v, -1});
        }else{
            all.push_back({l % v, 1});
            all.push_back({r % v + 1, -1});
        }
    }
    sort(all.begin(), all.end());
    ll pre = inf, st = 0;
    for(pair<ll,ll> item: all){
        if(st == 0) pre = item.first;
//        cout << item.first << ' ' << item.second << '\n';
        st += item.second;
        if(st == 0){
            ans += max(0ll, item.first - pre);
            pre = inf;
        }
    }
    cout << ans;
    return 0;
}

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

strange_device.cpp: In function 'int main()':
strange_device.cpp:16:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   16 |         freopen(__file_name ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   17 |         freopen(__file_name ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...