답안 #958264

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
958264 2024-04-05T09:11:51 Z MilosMilutinovic 도넛 (JOI14_ho_t3) C++14
100 / 100
93 ms 3156 KB
#include<bits/stdc++.h>
 
#define pb push_back
#define fi first
#define se second
#define mp make_pair
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef long double ld;
 
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,1:0;}
template <typename T> bool chkmax(T &x,T y){return x<y?x=y,1:0;}
 
ll readint(){
	ll x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}

int n;
int a[100005],nxt[100005];
ll pref[100005];

ll get(int l,int r){
	if(l<=r) return pref[r]-pref[l-1];
	else return pref[n]-(pref[l-1]-pref[r]);
}

bool check(ll x){
	if(pref[n]<x) return false;
	int ptr=1;
	for(int i=1;i<=n;i++){
		while(get(i,ptr)<x) ptr=(ptr%n)+1;
		nxt[i]=ptr;
		if(ptr==i) ptr=(ptr%n)+1;
	}
	for(int i=1;i<=n;i++){
		ll a=get(i,nxt[i]);
		ll b=get((nxt[i]%n)+1,nxt[(nxt[i]%n)+1]);
		ll c=get(nxt[(nxt[i]%n)+1]%n+1,nxt[nxt[(nxt[i]%n)+1]%n+1]);
		if(a+b+c<=pref[n]) return true;
	}
	return false;
}

int main(){
	n=readint();
	for(int i=1;i<=n;i++) a[i]=readint();
	for(int i=1;i<=n;i++) pref[i]=pref[i-1]+a[i];
	ll l=0,r=1e17,ans=0;
	while(l<=r){
		ll mid=(l+r)/2;
		if(check(mid)) ans=mid,l=mid+1;
		else r=mid-1;
	}
	printf("%lld\n",ans);
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 500 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 500 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 500 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 4 ms 604 KB Output is correct
23 Correct 4 ms 604 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 4 ms 612 KB Output is correct
26 Correct 6 ms 604 KB Output is correct
27 Correct 7 ms 604 KB Output is correct
28 Correct 7 ms 604 KB Output is correct
29 Correct 6 ms 528 KB Output is correct
30 Correct 7 ms 604 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 4 ms 348 KB Output is correct
34 Correct 4 ms 588 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 344 KB Output is correct
7 Correct 0 ms 500 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 344 KB Output is correct
11 Correct 1 ms 344 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 344 KB Output is correct
15 Correct 1 ms 600 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 344 KB Output is correct
19 Correct 1 ms 344 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 4 ms 604 KB Output is correct
22 Correct 4 ms 604 KB Output is correct
23 Correct 4 ms 604 KB Output is correct
24 Correct 4 ms 604 KB Output is correct
25 Correct 4 ms 612 KB Output is correct
26 Correct 6 ms 604 KB Output is correct
27 Correct 7 ms 604 KB Output is correct
28 Correct 7 ms 604 KB Output is correct
29 Correct 6 ms 528 KB Output is correct
30 Correct 7 ms 604 KB Output is correct
31 Correct 4 ms 348 KB Output is correct
32 Correct 4 ms 348 KB Output is correct
33 Correct 4 ms 348 KB Output is correct
34 Correct 4 ms 588 KB Output is correct
35 Correct 4 ms 348 KB Output is correct
36 Correct 91 ms 3156 KB Output is correct
37 Correct 85 ms 2948 KB Output is correct
38 Correct 83 ms 2944 KB Output is correct
39 Correct 86 ms 2948 KB Output is correct
40 Correct 86 ms 2904 KB Output is correct
41 Correct 88 ms 2920 KB Output is correct
42 Correct 86 ms 2908 KB Output is correct
43 Correct 89 ms 2908 KB Output is correct
44 Correct 84 ms 2940 KB Output is correct
45 Correct 93 ms 2908 KB Output is correct
46 Correct 39 ms 2140 KB Output is correct
47 Correct 39 ms 2136 KB Output is correct
48 Correct 39 ms 2136 KB Output is correct