# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1097119 | vjudge1 | Xor Sort (eJOI20_xorsort) | C++17 | 1 ms | 344 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include "bits/stdc++.h"
const signed MOD = 1e9 + 7;
const signed mod = 998244353;
using namespace std;
#define all(x) x.begin(), x.end()
#define ld long double
#define ll long long
#define pb push_back
#define mp make_pair
#define co cout <<
#define S second
#define F first
ll n, a[1000001];
bool sol(ll x) {
ll t = x;
vector<pair<ll, ll>> s;
for (int i = 0; i < n * 2; i++) {
if (a[i] <= t) {
t += a[i];
while (s.size() && s.back().F <= t) {
t += s.back().S;
s.pop_back();
}
}
else {
s.pb(mp(a[i], t - x + a[i]));
t = x;
}
}
return (s.empty());
}
void solve() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i + n] = a[i];
}
ll l = 0, r = 1e13;
while (l < r) {
ll m = l + r >> 1;
if (sol(m)) r = m;
else l = m + 1;
}
co l;
}
signed main() {
cin.tie(0)->sync_with_stdio(0);
signed t = 1;
// cin >> t;
while (t--) solve();
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |