Submission #469940

# Submission time Handle Problem Language Result Execution time Memory
469940 2021-09-02T11:20:31 Z cpp219 Hacker (BOI15_hac) C++14
100 / 100
79 ms 10692 KB
#include<bits/stdc++.h>
#define ll int
#define ld long double
#define fs first
#define sc second
#define debug(y) cout<<y,exit(0)
using namespace std;
typedef pair<ll,ll> LL;
const ll N = 1e6 + 9;
const ll mod = 998244353;

ll n,a[N],pre[N],val[N],take,ans;

ll cal(ll l,ll r){
    if (l <= r) return pre[r] - pre[l - 1];
    return pre[r] + pre[n] - pre[l - 1];
}

int main(){
    ios_base::sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
    #define task "test"
    if (fopen(task".inp","r")){
        freopen(task".inp","r",stdin);
        //freopen(task".out","w",stdout);
    }
    cin>>n; take = (n + 1)/2;
    for (ll i = 1;i <= n;i++) cin>>a[i],pre[i] = pre[i - 1] + a[i];
    //cout<<cal(4,1)<<"x"; return 0;
    for (ll i = 1;i <= n;i++){
        ll l = i,r = i + take - 1; if (r > n) r -= n;
        //cout<<l<<" "<<r<<" "<<cal(l,r)<<"\n";
        val[i] = cal(l,r);
    }
    for (ll i = n + 1;i <= 2*n;i++) val[i] = val[i - n];
    //for (ll i = 1;i <= n;i++) cout<<val[i]<<" "; return 0;
    deque<ll> dq;
    for (ll i = 1;i <= 2*n;i++){
        while(!dq.empty() && val[i] <= val[dq.back()]) dq.pop_back();
        while(!dq.empty() && i - dq.front() + 1 > take) dq.pop_front();
        dq.push_back(i);
        if (i >= take) ans = max(ans,val[dq.front()]);
    }
    cout<<ans;
}

/* stuff you should look for
    * int overflow,array bound
    * special cases (n = 1?)
    * do smth instead of nothing and stay organized
    * WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
*/

Compilation message

hac.cpp: In function 'int main()':
hac.cpp:23:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         freopen(task".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 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 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 12 ms 1944 KB Output is correct
5 Correct 28 ms 4108 KB Output is correct
6 Correct 37 ms 5308 KB Output is correct
7 Correct 48 ms 6348 KB Output is correct
8 Correct 79 ms 10236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 316 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 324 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 0 ms 332 KB Output is correct
16 Correct 0 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 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 2 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 0 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 0 ms 332 KB Output is correct
33 Correct 0 ms 332 KB Output is correct
34 Correct 1 ms 332 KB Output is correct
35 Correct 12 ms 1944 KB Output is correct
36 Correct 28 ms 4108 KB Output is correct
37 Correct 37 ms 5308 KB Output is correct
38 Correct 48 ms 6348 KB Output is correct
39 Correct 79 ms 10236 KB Output is correct
40 Correct 2 ms 460 KB Output is correct
41 Correct 3 ms 716 KB Output is correct
42 Correct 5 ms 848 KB Output is correct
43 Correct 28 ms 4312 KB Output is correct
44 Correct 71 ms 10324 KB Output is correct
45 Correct 14 ms 2252 KB Output is correct
46 Correct 42 ms 6304 KB Output is correct
47 Correct 69 ms 10204 KB Output is correct
48 Correct 55 ms 10532 KB Output is correct
49 Correct 58 ms 10692 KB Output is correct
50 Correct 58 ms 10692 KB Output is correct