Submission #723683

# Submission time Handle Problem Language Result Execution time Memory
723683 2023-04-14T07:30:50 Z MurotY Hacker (BOI15_hac) C++14
60 / 100
44 ms 8964 KB
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("avx,avx2")
#include <bits/stdc++.h>
#define ios ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define all(a) a.begin(), a.end()
#define sz size()
using namespace std;
const double pi = 2 * acos(0.0);
const ll N=1e6+7, M=998244353;

ll a[N], pr[N];
void solve()
{
	int n;
	cin >> n;
	for (int i=0;i<n;i++) {
	     cin >> a[i];
		pr[i]=pr[max(0, i-1)]+a[i];
	}
	if (n > 5000){
	     ll ans=0;
	     for (int i=0;i<1;i++){
		     int res=(n+1)/2;
		     ll mn=1e18;
		     for (int j=0;j<res;j++){
			
			     int l=(i-1+n) % n, r=i;
			     ll sum=0;
			     int lf;
			     if ((l-j+1) >= 0 && j > 0){
				     lf=l-j+1;
				     if (lf == 0) sum+=pr[l];
				     else sum+=pr[l]-pr[lf-1];
			     }
			     else if (j > 0){
				     sum+=pr[l];
				     lf=(l-j+1+n) % n;
				     if (lf == 0) sum+=pr[n-1];
				     else sum+=pr[n-1]-pr[lf-1];
			     }
			     int j1=res-j; l=i;
			     if ((l+j1-1) < n && j1 > 0){
				     lf=l+j1-1;
				     if (r == 0) sum+=pr[lf];
				     else sum+=pr[lf]-pr[r-1];
			     }
			     else if (j1 > 0){
				     if (r == 0) sum+=pr[n-1];
				     else sum+=pr[n-1]-pr[r-1];
				     lf=(i+j1-1) % n;
				     sum+=pr[lf];
			     }	
			     mn=min(mn, sum);
		     }
		     ans=max(ans, mn);
	     }
	     cout << ans;
	     return ;	
	}
	ll ans=0;
	for (int i=0;i<n;i++){
		int res=(n+1)/2;
		ll mn=1e18;
		for (int j=0;j<res;j++){
			
			int l=(i-1+n) % n, r=i;
			ll sum=0;
			int lf;
			if ((l-j+1) >= 0 && j > 0){
				lf=l-j+1;
				if (lf == 0) sum+=pr[l];
				else sum+=pr[l]-pr[lf-1];
			}
			else if (j > 0){
				sum+=pr[l];
				lf=(l-j+1+n) % n;
				if (lf == 0) sum+=pr[n-1];
				else sum+=pr[n-1]-pr[lf-1];
			}
			int j1=res-j; l=i;
		//	if (i == 0) cout << j <<" " << j1 << "\n";
			if ((l+j1-1) < n && j1 > 0){
				lf=l+j1-1;
				if (r == 0) sum+=pr[lf];
				else sum+=pr[lf]-pr[r-1];
			}
			else if (j1 > 0){
				if (r == 0) sum+=pr[n-1];
				else sum+=pr[n-1]-pr[r-1];
				lf=(i+j1-1) % n;
				sum+=pr[lf];
			}	
		//	cout << sum << "\n"; 
			mn=min(mn, sum);
		}
		ans=max(ans, mn);
	}
	cout << ans;
	return ;
}
int main(){
	ios;
	int t=1;	
//	cin >> t;
	while (t--){ 
	    solve();
	    cout << "\n";
	}
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 17 ms 340 KB Output is correct
23 Correct 44 ms 420 KB Output is correct
24 Correct 17 ms 340 KB Output is correct
25 Correct 44 ms 340 KB Output is correct
26 Correct 44 ms 420 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 328 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 43 ms 340 KB Output is correct
31 Correct 43 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 43 ms 344 KB Output is correct
4 Correct 6 ms 1876 KB Output is correct
5 Correct 18 ms 3936 KB Output is correct
6 Correct 19 ms 5128 KB Output is correct
7 Correct 22 ms 5828 KB Output is correct
8 Correct 39 ms 8964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 324 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 328 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 2 ms 340 KB Output is correct
21 Correct 2 ms 340 KB Output is correct
22 Correct 17 ms 340 KB Output is correct
23 Correct 44 ms 420 KB Output is correct
24 Correct 17 ms 340 KB Output is correct
25 Correct 44 ms 340 KB Output is correct
26 Correct 44 ms 420 KB Output is correct
27 Correct 0 ms 212 KB Output is correct
28 Correct 0 ms 328 KB Output is correct
29 Correct 1 ms 212 KB Output is correct
30 Correct 43 ms 340 KB Output is correct
31 Correct 43 ms 340 KB Output is correct
32 Correct 1 ms 328 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 43 ms 344 KB Output is correct
35 Correct 6 ms 1876 KB Output is correct
36 Correct 18 ms 3936 KB Output is correct
37 Correct 19 ms 5128 KB Output is correct
38 Correct 22 ms 5828 KB Output is correct
39 Correct 39 ms 8964 KB Output is correct
40 Incorrect 1 ms 468 KB Output isn't correct
41 Halted 0 ms 0 KB -