Submission #319742

# Submission time Handle Problem Language Result Execution time Memory
319742 2020-11-06T10:39:05 Z soroush Feast (NOI19_feast) C++14
71 / 100
441 ms 8164 KB
//*
#pragma GCC optimize("O2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
//*/
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int  ,int > pii;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const ll maxn  = 3e5+100;
const ll mod =1e9+7;
const ld PI = acos((ld)-1);

#define int ll
#define pb push_back
#define endl '\n'
#define dokme(x) cout << x , exit(0)
#define migmig ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define ms(x , y) memset(x , y , sizeof x)
ll pw(ll a, ll b, ll md = mod){ll res = 1;while(b){if(b&1){res=(a*res)%md;}a=(a*a)%md;b>>=1;}return(res);}

int n , k;
ll dp[maxn];
ll sum[maxn];
int a[maxn];

struct segment{
	int seg[maxn*4];
	int lazy[maxn*4];
	void build(int v = 1  , int l = 1 , int  r = n + 1){
		if(r - l == 1){
			seg[v] = dp[l] - sum[l];
			return;
		}
		int mid = (l + r) / 2;
		build(2*v , l , mid);
		build(2*v + 1 , mid , r);
		seg[v] = max(seg[2*v] , seg[2*v + 1]);
	}
	void shift(int v , int l , int r){
		seg[v] += lazy[v];
		if(r - l > 1)
			lazy[2*v] += lazy[v] , lazy[2*v + 1] += lazy[v];
		lazy[v] = 0;
	}
	void update(int L , int R , int x, int v = 1 , int l = 1 , int r = n + 1){
		shift(v , l , r);
		if(r <= L or R <= l)
			return;
		if(L <= l and r <= R){
			lazy[v] += x;
			shift(v , l , r);
			return;
		}
		int mid = (l + r) / 2;
		update(L , R  , x , 2*v , l , mid);
		update(L , R , x , 2*v + 1 , mid , r);
		seg[v] = max(seg[2*v] , seg[2*v + 1]);
	}
	int query(int L , int R , int v = 1 , int l = 1 , int r = n + 1){
		shift(v , l , r);
		if(r <= L or R <= l)
			return(0);
		if(L <= l and r <= R)
			return(seg[v]);
		int mid = (l + r)/2;
		return(max(query(L , R , 2*v , l , mid) , query(L , R , 2*v + 1, mid , r)));
	}
};

segment seg; //shans 100

void sub1(){ //10 + 11 (+ 20 ?) 
	ll mn = 0;
	for(int i = 1 ; i <= n ; i ++)
		dp[i] = max({dp[i] , dp[i - 1] , sum[i] - mn}) , mn = min(mn , sum[i]);
	for(int j = 2 ; j <= k ; j ++){
		seg.build();
		for(int i = 1 ; i <= n ; i  ++ )
			dp[i] = max(dp[i-1] , sum[i] + seg.query(1 , i));
	}
    dokme(dp[n]);
}

void sub2(){ //18
	ll ans = 0;
	ll mn = 0;
	for(int i = 1 ; i <= n ; i ++)
		ans = max(ans , sum[i] - mn) , mn = min(mn , sum[i]);
	dokme(ans);
}

void sub3(){ //8
	ll ans = 0;
	for(int i = 1 ; i <= n ; i ++)
		ans += max(0LL , a[i]);
	dokme(ans);
}

void sub4(){ //4
	dokme(sum[n]);
}

int32_t main(){
    migmig;
    cin >> n >> k;
    int cnt = 0;
    for(int i = 1 ; i <= n ; i ++)
		cin >> a[i] , cnt+=(a[i] < 0);
	for(int i = 1;  i <= n ; i ++)
		sum[i] = sum[i-1] + a[i];
	if(n <= 2000 and k <= 2000){
		sub1();
	}
	if(*min_element(a+1 , a + n + 1) >= 0)
		sub4();
	if(k == 1){
		sub2();
	}
	if(cnt <= 1){
		sub3();
	}
	dokme("8===o");
    return(0);
}
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7908 KB Output is correct
2 Correct 36 ms 8044 KB Output is correct
3 Correct 36 ms 7908 KB Output is correct
4 Correct 36 ms 7908 KB Output is correct
5 Correct 44 ms 7908 KB Output is correct
6 Correct 38 ms 7780 KB Output is correct
7 Correct 36 ms 7780 KB Output is correct
8 Correct 36 ms 7908 KB Output is correct
9 Correct 37 ms 7776 KB Output is correct
10 Correct 37 ms 7780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 6124 KB Output is correct
2 Correct 26 ms 6252 KB Output is correct
3 Correct 26 ms 6124 KB Output is correct
4 Correct 24 ms 6124 KB Output is correct
5 Correct 38 ms 7780 KB Output is correct
6 Correct 24 ms 5996 KB Output is correct
7 Correct 25 ms 6252 KB Output is correct
8 Correct 38 ms 7908 KB Output is correct
9 Correct 36 ms 7660 KB Output is correct
10 Correct 25 ms 6116 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 40 ms 8036 KB Output is correct
2 Correct 40 ms 7916 KB Output is correct
3 Correct 42 ms 8036 KB Output is correct
4 Correct 39 ms 8044 KB Output is correct
5 Correct 52 ms 8036 KB Output is correct
6 Correct 42 ms 8036 KB Output is correct
7 Correct 40 ms 8160 KB Output is correct
8 Correct 40 ms 8036 KB Output is correct
9 Correct 40 ms 8164 KB Output is correct
10 Correct 41 ms 8036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 360 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 396 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 1 ms 396 KB Output is correct
8 Correct 1 ms 364 KB Output is correct
9 Correct 1 ms 364 KB Output is correct
10 Correct 1 ms 492 KB Output is correct
11 Correct 2 ms 364 KB Output is correct
12 Correct 3 ms 364 KB Output is correct
13 Correct 1 ms 364 KB Output is correct
14 Correct 2 ms 360 KB Output is correct
15 Correct 2 ms 364 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 2 ms 364 KB Output is correct
18 Correct 1 ms 364 KB Output is correct
19 Correct 1 ms 364 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 53 ms 492 KB Output is correct
22 Correct 441 ms 612 KB Output is correct
23 Correct 102 ms 492 KB Output is correct
24 Correct 59 ms 492 KB Output is correct
25 Correct 80 ms 492 KB Output is correct
26 Correct 48 ms 620 KB Output is correct
27 Correct 75 ms 696 KB Output is correct
28 Correct 9 ms 492 KB Output is correct
29 Correct 9 ms 492 KB Output is correct
30 Correct 2 ms 492 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 35 ms 7908 KB Output is correct
2 Correct 36 ms 8044 KB Output is correct
3 Correct 36 ms 7908 KB Output is correct
4 Correct 36 ms 7908 KB Output is correct
5 Correct 44 ms 7908 KB Output is correct
6 Correct 38 ms 7780 KB Output is correct
7 Correct 36 ms 7780 KB Output is correct
8 Correct 36 ms 7908 KB Output is correct
9 Correct 37 ms 7776 KB Output is correct
10 Correct 37 ms 7780 KB Output is correct
11 Correct 25 ms 6124 KB Output is correct
12 Correct 26 ms 6252 KB Output is correct
13 Correct 26 ms 6124 KB Output is correct
14 Correct 24 ms 6124 KB Output is correct
15 Correct 38 ms 7780 KB Output is correct
16 Correct 24 ms 5996 KB Output is correct
17 Correct 25 ms 6252 KB Output is correct
18 Correct 38 ms 7908 KB Output is correct
19 Correct 36 ms 7660 KB Output is correct
20 Correct 25 ms 6116 KB Output is correct
21 Correct 40 ms 8036 KB Output is correct
22 Correct 40 ms 7916 KB Output is correct
23 Correct 42 ms 8036 KB Output is correct
24 Correct 39 ms 8044 KB Output is correct
25 Correct 52 ms 8036 KB Output is correct
26 Correct 42 ms 8036 KB Output is correct
27 Correct 40 ms 8160 KB Output is correct
28 Correct 40 ms 8036 KB Output is correct
29 Correct 40 ms 8164 KB Output is correct
30 Correct 41 ms 8036 KB Output is correct
31 Correct 1 ms 364 KB Output is correct
32 Correct 1 ms 364 KB Output is correct
33 Correct 1 ms 396 KB Output is correct
34 Correct 1 ms 364 KB Output is correct
35 Correct 1 ms 364 KB Output is correct
36 Correct 1 ms 492 KB Output is correct
37 Correct 1 ms 396 KB Output is correct
38 Correct 1 ms 364 KB Output is correct
39 Correct 1 ms 364 KB Output is correct
40 Correct 1 ms 492 KB Output is correct
41 Correct 2 ms 364 KB Output is correct
42 Correct 3 ms 364 KB Output is correct
43 Correct 1 ms 364 KB Output is correct
44 Correct 2 ms 360 KB Output is correct
45 Correct 2 ms 364 KB Output is correct
46 Correct 1 ms 364 KB Output is correct
47 Correct 2 ms 364 KB Output is correct
48 Correct 1 ms 364 KB Output is correct
49 Correct 1 ms 364 KB Output is correct
50 Correct 1 ms 384 KB Output is correct
51 Correct 53 ms 492 KB Output is correct
52 Correct 441 ms 612 KB Output is correct
53 Correct 102 ms 492 KB Output is correct
54 Correct 59 ms 492 KB Output is correct
55 Correct 80 ms 492 KB Output is correct
56 Correct 48 ms 620 KB Output is correct
57 Correct 75 ms 696 KB Output is correct
58 Correct 9 ms 492 KB Output is correct
59 Correct 9 ms 492 KB Output is correct
60 Correct 2 ms 492 KB Output is correct
61 Incorrect 40 ms 7908 KB Output isn't correct
62 Halted 0 ms 0 KB -