#include <bits/stdc++.h>
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define bp __builtin_popcount
#define fir first
#define sec second
#define pss pair<short, short>
#define pii pair<int, int>
#define pll pair<ll, ll>
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
using namespace std;
int dx[4]={0, 1, 0, -1}, dy[4]={1, 0, -1 , 0};
const int mxN=100005;
const int mxM=350;
const int mxK=350;
const ll MOD=998244353;
const ll INF=100000000000001;
int N;
ll A[mxN];
ll sum[mxN], cnt[mxN];
bool solv(ll num)
{
for(int i=0;i<N;i++) cnt[i]=sum[i]=0;
while(sum[0]<num)
{
sum[0]+=A[cnt[0]];
cnt[0]++;
}
for(int i=1;i<N;i++)
{
sum[i]=sum[i-1]-A[i-1];
cnt[i]=cnt[i-1]-1;
while(sum[i]<num)
{
sum[i]+=A[(i+cnt[i])%N];
cnt[i]++;
}
}
for(int i=0;i<N;i++)
{
int t1=i;
int t2=(t1+cnt[t1])%N;
int t3=(t2+cnt[t2])%N;
int tsum=cnt[t1]+cnt[t2]+cnt[t3];
if(tsum<=N) return true;
}
return false;
}
int main()
{
gibon
cin >> N;
for(int i=0;i<N;i++) cin >> A[i];
ll s=INF, e=0;
for(int i=0;i<N;i++) s=min(s, A[i]);
for(int i=0;i<N;i++) e+=A[i];
while(s!=e)
{
ll mid=(s+e)/2;
if(solv(mid)) s=mid+1;
else e=mid;
}
cout << s-1;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
460 KB |
Output is correct |
22 |
Correct |
5 ms |
552 KB |
Output is correct |
23 |
Correct |
4 ms |
460 KB |
Output is correct |
24 |
Correct |
5 ms |
460 KB |
Output is correct |
25 |
Correct |
5 ms |
460 KB |
Output is correct |
26 |
Correct |
8 ms |
588 KB |
Output is correct |
27 |
Correct |
7 ms |
588 KB |
Output is correct |
28 |
Correct |
7 ms |
588 KB |
Output is correct |
29 |
Correct |
7 ms |
596 KB |
Output is correct |
30 |
Correct |
7 ms |
592 KB |
Output is correct |
31 |
Correct |
5 ms |
460 KB |
Output is correct |
32 |
Correct |
4 ms |
460 KB |
Output is correct |
33 |
Correct |
4 ms |
460 KB |
Output is correct |
34 |
Correct |
4 ms |
460 KB |
Output is correct |
35 |
Correct |
5 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
312 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
316 KB |
Output is correct |
4 |
Correct |
0 ms |
320 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
324 KB |
Output is correct |
7 |
Correct |
0 ms |
204 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
320 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
2 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
1 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
1 ms |
332 KB |
Output is correct |
21 |
Correct |
4 ms |
460 KB |
Output is correct |
22 |
Correct |
5 ms |
552 KB |
Output is correct |
23 |
Correct |
4 ms |
460 KB |
Output is correct |
24 |
Correct |
5 ms |
460 KB |
Output is correct |
25 |
Correct |
5 ms |
460 KB |
Output is correct |
26 |
Correct |
8 ms |
588 KB |
Output is correct |
27 |
Correct |
7 ms |
588 KB |
Output is correct |
28 |
Correct |
7 ms |
588 KB |
Output is correct |
29 |
Correct |
7 ms |
596 KB |
Output is correct |
30 |
Correct |
7 ms |
592 KB |
Output is correct |
31 |
Correct |
5 ms |
460 KB |
Output is correct |
32 |
Correct |
4 ms |
460 KB |
Output is correct |
33 |
Correct |
4 ms |
460 KB |
Output is correct |
34 |
Correct |
4 ms |
460 KB |
Output is correct |
35 |
Correct |
5 ms |
460 KB |
Output is correct |
36 |
Correct |
93 ms |
3532 KB |
Output is correct |
37 |
Correct |
107 ms |
3612 KB |
Output is correct |
38 |
Correct |
95 ms |
3608 KB |
Output is correct |
39 |
Correct |
90 ms |
3556 KB |
Output is correct |
40 |
Correct |
100 ms |
3612 KB |
Output is correct |
41 |
Correct |
94 ms |
3532 KB |
Output is correct |
42 |
Correct |
92 ms |
3532 KB |
Output is correct |
43 |
Correct |
100 ms |
3612 KB |
Output is correct |
44 |
Correct |
92 ms |
3532 KB |
Output is correct |
45 |
Correct |
101 ms |
3624 KB |
Output is correct |
46 |
Correct |
40 ms |
2764 KB |
Output is correct |
47 |
Correct |
41 ms |
2764 KB |
Output is correct |
48 |
Correct |
40 ms |
2764 KB |
Output is correct |