Submission #140648

#TimeUsernameProblemLanguageResultExecution timeMemory
140648HellAngelBridges (APIO19_bridges)C++14
0 / 100
16 ms2040 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; }

Compilation message (stderr)

bridges.cpp: In function 'int32_t main()':
bridges.cpp:44:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for(int i = 1; i < vt.size(); i++)
                    ~~^~~~~~~~~~~
bridges.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);
                                ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bridges.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...