제출 #568698

#제출 시각아이디문제언어결과실행 시간메모리
568698joshjms이상한 기계 (APIO19_strange_device)C++14
5 / 100
616 ms48952 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define ld long double #define pb push_back #define fi first #define se second #define debug(x) cout << #x << " => " << x << "\n"; const long long mod = 1e9 + 7; const long long MAX = 1e18; int n, a, b, L[1000005], R[1000005], s, m; vector <pair<int,int>> ls; int cnt, prv, ans; void solve () { cin >> n >> a >> b; for(int i = 1; i <= n; i++) { cin >> L[i] >> R[i]; s += R[i] - L[i] + 1; } m = a * b; for(int i = 1; i <= n; i++) { if(R[i] - L[i] + 1 >= m) { cout << m << "\n"; return; } } for(int i = 1; i <= n; i++) { L[i] %= m; R[i] %= m; if(R[i] < L[i]) { ls.pb({L[i], 0}); ls.pb({m, 1}); ls.pb({0, 0}); ls.pb({R[i] + 1, 1}); } else { ls.pb({L[i], 0}); ls.pb({R[i] + 1, 1}); } } sort(ls.begin(), ls.end()); cnt = 0, prv = -1; // for(auto i : ls) cout << i.fi << " "; // cout << "\n"; for(int i = 0; i < ls.size(); i++) { if(ls[i].se == 0) cnt++; else cnt--; if(i < ls.size() - 1 && ls[i].fi == ls[i + 1].fi) continue; if(cnt > 0 && prv == -1) {prv = ls[i].fi;} if(cnt == 0 && prv != -1) {ans += ls[i].fi - prv; prv = -1;} } cout << ans << "\n"; } signed main () { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); solve(); }

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

strange_device.cpp: In function 'void solve()':
strange_device.cpp:57:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int i = 0; i < ls.size(); i++) {
      |                    ~~^~~~~~~~~~~
strange_device.cpp:61:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |         if(i < ls.size() - 1 && ls[i].fi == ls[i + 1].fi) continue;
      |            ~~^~~~~~~~~~~~~~~
#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...