# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
470010 |
2021-09-02T15:05:05 Z |
Killer2501 |
Hacker (BOI15_hac) |
C++14 |
|
221 ms |
103116 KB |
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll N = 5e5+5;
const int base = 313;
ll n, m, t, k, T, ans, q, tong, c[N], a[N], b[N], h[N], P[N][21];
vector<ll> adj[N], kq;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
ll sum(ll l, ll r)
{
if(l <= r)return b[r] - b[l-1];
return b[r] + b[n] - b[l-1];
}
ll mx(ll l, ll r)
{
ll log = log2(r-l+1);
return max(P[l][log], P[r-(1<<log)+1][log]);
}
ll get(ll l, ll r)
{
if(l <= r)return mx(l, r);
return max(mx(1, r), mx(l, n));
}
void sol()
{
cin >> n;
for(int i = 1; i <= n; i ++)
{
cin >> a[i];
b[i] = b[i-1] + a[i];
}
for(int i = 1; i <= n; i ++)
{
int j = i + n/2 - 1;
if(j > n)j -= n;
P[i][0] = sum(i, j);
}
for(int j = 1; j <= 20; j ++)
{
for(int i = 1; i+(1<<j)-1 <= n; i ++)P[i][j] = max(P[i][j-1], P[i+(1<<(j-1))][j-1]);
}
for(int i = 1; i <= n; i ++)
{
int l = i + 1, r = i - n / 2;
if(l > n)l -= n;
if(r <= 0)r += n;
ans = max(ans, b[n]- get(l, r));
}
cout << ans;
}
int main()
{
if(fopen(task".in", "r"))
{
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message
hac.cpp: In function 'int main()':
hac.cpp:72:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
72 | freopen(task".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
hac.cpp:73:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
73 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Output is correct |
2 |
Correct |
7 ms |
11980 KB |
Output is correct |
3 |
Correct |
7 ms |
11980 KB |
Output is correct |
4 |
Correct |
7 ms |
11980 KB |
Output is correct |
5 |
Correct |
7 ms |
11980 KB |
Output is correct |
6 |
Correct |
7 ms |
11980 KB |
Output is correct |
7 |
Correct |
7 ms |
12108 KB |
Output is correct |
8 |
Correct |
8 ms |
12108 KB |
Output is correct |
9 |
Correct |
7 ms |
12108 KB |
Output is correct |
10 |
Correct |
7 ms |
12108 KB |
Output is correct |
11 |
Correct |
7 ms |
12108 KB |
Output is correct |
12 |
Correct |
7 ms |
12108 KB |
Output is correct |
13 |
Correct |
7 ms |
12072 KB |
Output is correct |
14 |
Correct |
7 ms |
11980 KB |
Output is correct |
15 |
Correct |
7 ms |
11980 KB |
Output is correct |
16 |
Correct |
7 ms |
12160 KB |
Output is correct |
17 |
Correct |
8 ms |
12108 KB |
Output is correct |
18 |
Correct |
8 ms |
12108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Output is correct |
2 |
Correct |
7 ms |
11980 KB |
Output is correct |
3 |
Correct |
7 ms |
11980 KB |
Output is correct |
4 |
Correct |
7 ms |
11980 KB |
Output is correct |
5 |
Correct |
7 ms |
11980 KB |
Output is correct |
6 |
Correct |
7 ms |
11980 KB |
Output is correct |
7 |
Correct |
7 ms |
12108 KB |
Output is correct |
8 |
Correct |
8 ms |
12108 KB |
Output is correct |
9 |
Correct |
7 ms |
12108 KB |
Output is correct |
10 |
Correct |
7 ms |
12108 KB |
Output is correct |
11 |
Correct |
7 ms |
12108 KB |
Output is correct |
12 |
Correct |
7 ms |
12108 KB |
Output is correct |
13 |
Correct |
7 ms |
12072 KB |
Output is correct |
14 |
Correct |
7 ms |
11980 KB |
Output is correct |
15 |
Correct |
7 ms |
11980 KB |
Output is correct |
16 |
Correct |
7 ms |
12160 KB |
Output is correct |
17 |
Correct |
8 ms |
12108 KB |
Output is correct |
18 |
Correct |
8 ms |
12108 KB |
Output is correct |
19 |
Correct |
7 ms |
12136 KB |
Output is correct |
20 |
Correct |
7 ms |
12236 KB |
Output is correct |
21 |
Correct |
7 ms |
12136 KB |
Output is correct |
22 |
Correct |
8 ms |
12492 KB |
Output is correct |
23 |
Correct |
9 ms |
12876 KB |
Output is correct |
24 |
Correct |
8 ms |
12540 KB |
Output is correct |
25 |
Correct |
9 ms |
12876 KB |
Output is correct |
26 |
Correct |
8 ms |
12876 KB |
Output is correct |
27 |
Correct |
7 ms |
11980 KB |
Output is correct |
28 |
Correct |
7 ms |
11980 KB |
Output is correct |
29 |
Correct |
7 ms |
11980 KB |
Output is correct |
30 |
Correct |
10 ms |
12876 KB |
Output is correct |
31 |
Correct |
8 ms |
12888 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
12072 KB |
Output is correct |
2 |
Correct |
8 ms |
12108 KB |
Output is correct |
3 |
Correct |
9 ms |
12876 KB |
Output is correct |
4 |
Correct |
35 ms |
26488 KB |
Output is correct |
5 |
Correct |
84 ms |
48004 KB |
Output is correct |
6 |
Correct |
108 ms |
56976 KB |
Output is correct |
7 |
Correct |
126 ms |
67012 KB |
Output is correct |
8 |
Correct |
215 ms |
102976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
7 ms |
11980 KB |
Output is correct |
2 |
Correct |
7 ms |
11980 KB |
Output is correct |
3 |
Correct |
7 ms |
11980 KB |
Output is correct |
4 |
Correct |
7 ms |
11980 KB |
Output is correct |
5 |
Correct |
7 ms |
11980 KB |
Output is correct |
6 |
Correct |
7 ms |
11980 KB |
Output is correct |
7 |
Correct |
7 ms |
12108 KB |
Output is correct |
8 |
Correct |
8 ms |
12108 KB |
Output is correct |
9 |
Correct |
7 ms |
12108 KB |
Output is correct |
10 |
Correct |
7 ms |
12108 KB |
Output is correct |
11 |
Correct |
7 ms |
12108 KB |
Output is correct |
12 |
Correct |
7 ms |
12108 KB |
Output is correct |
13 |
Correct |
7 ms |
12072 KB |
Output is correct |
14 |
Correct |
7 ms |
11980 KB |
Output is correct |
15 |
Correct |
7 ms |
11980 KB |
Output is correct |
16 |
Correct |
7 ms |
12160 KB |
Output is correct |
17 |
Correct |
8 ms |
12108 KB |
Output is correct |
18 |
Correct |
8 ms |
12108 KB |
Output is correct |
19 |
Correct |
7 ms |
12136 KB |
Output is correct |
20 |
Correct |
7 ms |
12236 KB |
Output is correct |
21 |
Correct |
7 ms |
12136 KB |
Output is correct |
22 |
Correct |
8 ms |
12492 KB |
Output is correct |
23 |
Correct |
9 ms |
12876 KB |
Output is correct |
24 |
Correct |
8 ms |
12540 KB |
Output is correct |
25 |
Correct |
9 ms |
12876 KB |
Output is correct |
26 |
Correct |
8 ms |
12876 KB |
Output is correct |
27 |
Correct |
7 ms |
11980 KB |
Output is correct |
28 |
Correct |
7 ms |
11980 KB |
Output is correct |
29 |
Correct |
7 ms |
11980 KB |
Output is correct |
30 |
Correct |
10 ms |
12876 KB |
Output is correct |
31 |
Correct |
8 ms |
12888 KB |
Output is correct |
32 |
Correct |
8 ms |
12072 KB |
Output is correct |
33 |
Correct |
8 ms |
12108 KB |
Output is correct |
34 |
Correct |
9 ms |
12876 KB |
Output is correct |
35 |
Correct |
35 ms |
26488 KB |
Output is correct |
36 |
Correct |
84 ms |
48004 KB |
Output is correct |
37 |
Correct |
108 ms |
56976 KB |
Output is correct |
38 |
Correct |
126 ms |
67012 KB |
Output is correct |
39 |
Correct |
215 ms |
102976 KB |
Output is correct |
40 |
Correct |
10 ms |
13856 KB |
Output is correct |
41 |
Correct |
12 ms |
15692 KB |
Output is correct |
42 |
Correct |
15 ms |
17612 KB |
Output is correct |
43 |
Correct |
87 ms |
49040 KB |
Output is correct |
44 |
Correct |
221 ms |
103068 KB |
Output is correct |
45 |
Correct |
43 ms |
30412 KB |
Output is correct |
46 |
Correct |
128 ms |
67008 KB |
Output is correct |
47 |
Correct |
217 ms |
103060 KB |
Output is correct |
48 |
Correct |
216 ms |
102984 KB |
Output is correct |
49 |
Correct |
213 ms |
103060 KB |
Output is correct |
50 |
Correct |
213 ms |
103116 KB |
Output is correct |