제출 #1016320

#제출 시각아이디문제언어결과실행 시간메모리
1016320VMaksimoski008이상한 기계 (APIO19_strange_device)C++17
100 / 100
325 ms53960 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; const int mod = 1e9 + 7; int main() { ios_base::sync_with_stdio(false); cout.tie(0); cin.tie(0); ll n, A, B; cin >> n >> A >> B; ll P = min( (__int128_t)A / (__int128_t)__gcd(A, B + 1) * (__int128_t)B, (__int128_t)1e18 + 1 ); vector<pair<ll, ll> > st; for(int i=0; i<n; i++) { ll L, R; cin >> L >> R; if(R - L + 1 >= P) { cout << P << '\n'; return 0; } ll a = L % P, b = R % P; if(L == R) { st.push_back({ a, b }); } else if(a < b) { st.push_back({ a, b }); } else { st.push_back({ a, P - 1 }); st.push_back({ 0, b }); } } ll res = 0; sort(st.begin(), st.end()); ll left_end=st[0].first, right_end=st[0].second; for(int i=1; i<st.size(); i++) { if(st[i].first > right_end) { res += right_end - left_end + 1; left_end = st[i].first; right_end = st[i].second; } else { right_end = max(right_end, st[i].second); } } cout << res + right_end - left_end + 1 << '\n'; return 0; }

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

strange_device.cpp: In function 'int main()':
strange_device.cpp:40: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]
   40 |     for(int i=1; i<st.size(); 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...