QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#556170 | #2299. Heating Up | qwqqwqqwqe | WA | 7ms | 36588kb | C++17 | 2.7kb | 2024-09-10 15:35:12 | 2024-09-10 15:35:12 |
Judging History
answer
#include"bits/stdc++.h"
#define _det(...) fprintf(stderr,__VA_ARGS__)
#define Print(a) cerr<<a<<"\n"
#define IOS ios::sync_with_stdio(0);cin.tie(0)
#define Cases int T;cin>>T;while(T--)
#define Debug(in) cerr<<#in<<" = "<<(in)<<"\n"
#define Watch(in) Detect;Debug(in);
#define Detect _det("Passing [%s] in LINE %d\n",__FUNCTION__,__LINE__)
#define ll long long
using namespace std;
const int maxn = 1e6+5;
ll a[maxn];
ll p[maxn];
vector<int> E[maxn];
int n;
int vis[maxn];
int L[maxn]; int R[maxn];
void DFS (int u) {
for (int v: E[u]) {
if (vis[v]) continue;
vis[v] = true;
DFS(v);
}
}
int read () {
int x = 0;
char c = getchar();
while(c<'0' || c>'9'){
c = getchar();
}
while(c>='0' && c<='9'){
x = x*10+c-'0';
c = getchar();
}
return x;
}
int check (int mid) {
//Debug(mid);
for (int i=1;i<=n+n;i++) E[i].clear();
for (int i=1;i<=n+n;i++) {
int to = lower_bound(p+i,p+n+n+1,a[i]+p[i]-mid)-p;
if (to > i) R[i] = to;
else R[i] = i;
}
for (int i=1;i<=n+n;i++) {
int to = upper_bound(p+1,p+i+1,p[i-1]+mid-a[i])-p-1;
if (to < i) L[i] = to;
else L[i] = i;
}
pair<ll,ll> Rm = {-1e18,1e18};
for (int i=n+n;i>=1;i--) {
if (R[i] < Rm.second) {
Rm = {R[i],i};
}
if (Rm.first > R[i]) {
R[i] = Rm.first;
}
if (Rm.first <= R[i]) {
Rm = {R[i],i};
}
//Debug(R[i]);
}
pair<ll,ll> Lm = {1e18,-1e18}; //mx, from
for (int i=1;i<=n+n;i++) {
if (L[i] > Lm.second) {
Lm = {L[i],i};
}
if (Lm.first < L[i]) {
L[i] = Lm.first;
}
if (Lm.first >= L[i]) {
Lm = {L[i],i};
}
// Debug(L[i]);
}
for (int i=1;i<=n+n;i++) {
E[L[i]].push_back(i);
E[R[i]].push_back(i);
}
for (int i=1;i<=n+n;i++) {
vis[i] = false;
}
for (int i=1;i<=n+n;i++) {
if (a[i] <= mid) {
vis[i] = true;
DFS(i);
}
}
for (int i=1;i<=n+n;i++) {
if (!vis[i]) {
return false;
}
}
return true;
}
int main () {
n = read();
for (int i=1;i<=n;i++) {
a[i] = read();
a[i+n] = a[i];
}
for (int i=1;i<=n+n;i++) {
p[i] = p[i-1]+a[i];
}
p[n+n+1] = 1e18;
ll left = 0;
ll right = 1e13;
ll ans = -1;
while (left<=right) {
int mid = (left+right)/2;
if (check(mid)) {
right = mid-1;
ans = mid;
}
else left = mid+1;
}
printf("%lld", ans);
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 7ms
memory: 36588kb
input:
4 10 20 15 1
output:
10
result:
wrong answer 1st lines differ - expected: '9', found: '10'