제출 #258394

#제출 시각아이디문제언어결과실행 시간메모리
258394DS007이상한 기계 (APIO19_strange_device)C++14
35 / 100
850 ms33592 KiB
#include <bits/stdc++.h> using namespace std; #define int long long int n, a, b; bool overflow(int x, int y) { int result = x * y; return result / x != y; } int sum() { int ans = 0; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; ans += r - l + 1; } return ans; } int solveTestCase() { cin >> n >> a >> b; int temp = a / __gcd(a, b + 1); assert(a % __gcd(a, b + 1) == 0); if (overflow(temp, b)) return cout << sum(), 0; temp *= b; //cerr << temp << "\n"; vector<pair<int, int>> v; for (int i = 0; i < n; i++) { int l, r; cin >> l >> r; if (r - l + 1 >= temp) return cout << temp, 0; if (l % temp <= r % temp) v.emplace_back(l % temp, 1), v.emplace_back(r % temp + 1, 2); else v.emplace_back(l % temp, 1), v.emplace_back(temp, 2), v.emplace_back(0, 1), v.emplace_back(r % temp + 1, 2), assert(l % temp > r % temp + 1); } sort(v.begin(), v.end()); int ans = 0, d = 0, last = 0; for (auto i : v) { if (d == 0) last = i.first; if (i.second == 1) d++; else d--; assert(d >= 0); if (d == 0) ans += i.first - last; } cout << ans; } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int t = 1; //cin >> t; while (t--) solveTestCase(); }

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

strange_device.cpp: In function 'long long int solveTestCase()':
strange_device.cpp:65:1: warning: control reaches end of non-void function [-Wreturn-type]
 }
 ^
#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...