QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#815484 | #9879. ReTravel | ucup-team133# | WA | 0ms | 3644kb | C++23 | 1.9kb | 2024-12-15 14:52:10 | 2024-12-15 14:52:16 |
Judging History
answer
#include <bits/stdc++.h>
#ifdef LOCAL
#include <debug.hpp>
#else
#define debug(...) void(0)
#endif
template <class T> std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& e : v) {
is >> e;
}
return is;
}
template <class T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& v) {
for (std::string_view sep = ""; const auto& e : v) {
os << std::exchange(sep, " ") << e;
}
return os;
}
template <class T, class U = T> bool chmin(T& x, U&& y) {
return y < x and (x = std::forward<U>(y), true);
}
template <class T, class U = T> bool chmax(T& x, U&& y) {
return x < y and (x = std::forward<U>(y), true);
}
template <class T> void mkuni(std::vector<T>& v) {
std::ranges::sort(v);
auto result = std::ranges::unique(v);
v.erase(result.begin(), result.end());
}
template <class T> int lwb(const std::vector<T>& v, const T& x) {
return std::distance(v.begin(), std::ranges::lower_bound(v, x));
}
using namespace std;
using ll = long long;
bool check(pair<int, int> s, pair<int, int> t) { return s.first <= t.first and s.second <= t.second; }
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout << fixed << setprecision(15);
int N;
cin >> N;
stack<pair<int, int>> st;
st.emplace(0, 0);
ll ans = 0;
for (; N--;) {
int X, Y;
cin >> X >> Y;
if (check(st.top(), {X, Y})) {
auto p = st.top();
ans += (X + Y) - (p.first + p.second);
st.emplace(X, Y);
} else {
pair<int, int> pre;
while (not check(st.top(), {X, Y})) {
pre = st.top();
st.pop();
}
int nx = min(X, pre.first), ny = min(Y, pre.second);
ans += (X + Y) - (nx + ny);
st.emplace(nx, ny);
st.emplace(X, Y);
}
}
cout << ans << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3620kb
input:
2 3 3 1 2
output:
6
result:
ok "6"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
3 2 2 3 3 1 3
output:
7
result:
ok "7"
Test #3:
score: -100
Wrong Answer
time: 0ms
memory: 3612kb
input:
500 906691059 413653999 813847339 955892128 451585301 43469773 278009742 548977048 521760889 434794718 985946604 841597326 891047768 325679554 511742081 384452587 626401695 957413342 975078788 234551094 541903389 149544006 302621084 150050891 811538590 101823753 663968655 858351976 268979133 9768326...
output:
233625568926
result:
wrong answer 1st words differ - expected: '202616034783', found: '233625568926'