QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#757423 | #2299. Heating Up | KarL06 | RE | 0ms | 3740kb | C++20 | 1.6kb | 2024-11-17 07:01:39 | 2024-11-17 07:01:41 |
Judging History
answer
#ifdef DEBUG
#include"bits/dbg.h"
#else
#define dbg(...)
#endif
#include"bits/stdc++.h"
#define int long long
#define P pair<int,int>
#define x first
#define y second
using namespace std;
const int maxn = 5e5+5;
int s[maxn];
int n;
bool check (int mid) {
dbg(mid);
vector<P> v; //{ans, size}
for (int i=1;i<=n+n;i++) {
if (v.size() && (v.back().first <= mid || v.back().second > 1) && v.back().first+mid >= s[i]) {
P p = {v.back().first+s[i], v.back().second+1};
v.pop_back();
v.push_back(p);
}
else {
v.push_back({s[i], 1});
}
if (!(v.back().first <= mid || v.back().second > 1)) continue;
int sum = v.back().first;
int sz = v.back().second;
v.pop_back();
if (v.size() && v.back().first <= sum+mid) {
while (v.size() && v.back().first <= sum+mid) {
sum += v.back().first;
sz += v.back().second;
v.pop_back();
}
}
v.push_back({sum, sz});
}
for (auto e : v) {
if (e.second >= n) return true;
}
return false;
}
signed main () {
cin >> n;
for (int i=1;i<=n;i++) {
cin >> s[i];
s[n+i] = s[i];
}
int l = 1;
int r = 1e13;
int ans = -1;
while (l <= r) {
int mid = (l+r)/2;
if (check(mid)) {
r = mid-1;
ans = mid;
}
else {
l = mid+1;
}
}
dbg(check(2));
dbg(check(4));
dbg(check(12));
cout << ans << endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3740kb
input:
4 10 20 15 1
output:
9
result:
ok single line: '9'
Test #2:
score: -100
Runtime Error
input:
500000 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...