제출 #200513

#제출 시각아이디문제언어결과실행 시간메모리
200513HellAngelStrange Device (APIO19_strange_device)C++14
100 / 100
757 ms33844 KiB
#include <bits/stdc++.h>
#define int long long
const int inf = (int)1e18 + 69;
using namespace std;
 
const int maxn = 1e6 + 7;
 
int n, l[maxn], r[maxn], a, b, sum = 0, IT[4 * maxn];
 
vector<pair<int, int>> vt;
 
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
    cin >> n >> a >> b;
    for(int i = 1; i <= n; i++) cin >> l[i] >> r[i], sum += r[i] - l[i] + 1;
    int Dist = a / __gcd(a, b + 1);
    if(inf / Dist < b) return cout << sum, 0;
    Dist *= b;
    /// tối đa có dist giá trị
    for(int i = 1; i <= n; i++)
    {
        int gau = l[i] % Dist;
        int meo = r[i] % Dist;
        if(r[i] - l[i] + 1 >= Dist) return cout << Dist << '\n', 0;
        else
        {
            if(gau <= meo)
            {
                vt.push_back({gau, meo});
            }
            else
            {
                vt.push_back({gau, Dist - 1});
                vt.push_back({0, meo});
            }
        }
    }
    sort(vt.begin(),vt.end());
    assert(vt.size() != 0);
    int ans1 = vt[0].second - vt[0].first + 1, curl1 = vt[0].second + 1;
    for(int i = 1; i < vt.size(); i++)
    {
        if(vt[i].second >= curl1)
        {
            ans1 += vt[i].second - max(curl1, vt[i].first) + 1;
            curl1 = vt[i].second + 1;
        }
    }
    cout << ans1;
}

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

strange_device.cpp: In function 'int32_t main()':
strange_device.cpp:44:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < vt.size(); i++)
                    ~~^~~~~~~~~~~
strange_device.cpp:16:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
strange_device.cpp:16:63: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
#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...