# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
791534 |
2023-07-24T07:13:43 Z |
NguyenKhang |
Feast (NOI19_feast) |
C++17 |
|
1000 ms |
8016 KB |
//#pragma GCC optimize("Ofast,unroll-loops")
//#pragma GCC target("bmi,bmi2,lzcnt,popcnt")
//#pragma GCC target("avx2,popcnt,lzcnt,abm,bmi,bmi2,fma,tune=native")
//#pragma expected_value
//#pragma isolated_call
//#pragma disjoint
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
#define int long long
//#define double long double
#define Fi first
#define Se second
#define Rep(i,a,b) for (int i=a;i<=b;++i)
#define Repu(i,b,a) for (int i=b;i>=a;--i)
#define pb push_back
#define ms(a,i) memset(a,i,sizeof(a))
#define sz size()
#define mp make_pair
#define endl '\n'
#define sef setprecision(6)<<fixed
#define cer cout<<"cak"<<endl;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef vector<double> va;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<va> vva;
//const double EPS=1e-9;
const double PI=acos(-1);
const long long oo=1e18;
const int MN=3e5+5;
const int mod=1e9+7;
using cd=complex<double>;
//typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> index_set;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,k;
int a[MN];
int pre[MN];
int dp_before[MN], dp_now[MN];
void compute(int l,int r,int tl,int dr) {
if(l>r) return;
int mid = (l+r)/2;
ii maxx = {dp_before[mid], mid};
Rep(i,tl,min(dr,mid)) {
int temp = pre[mid] - pre[i];
maxx = max(maxx, ii(dp_before[i] + temp,i));
}
dp_now[mid] = maxx.Fi;
compute(l,mid-1,tl,maxx.Se); compute(mid+1,r,maxx.Se,dr);
}
signed main() {
//freopen(".inp","r",stdin); freopen(".out","w",stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>k;
if(n<=2000) {
Rep(i,1,n) cin>>a[i];
Rep(i,1,n) pre[i] = pre[i-1] + a[i];
int cek = 0;
Rep(step,1,k) {
Rep(i,1,n) {
dp_now[i] = max(dp_before[i], dp_now[i-1]);
Rep(j,0,i-1) dp_now[i] = max(dp_now[i], dp_before[j] + pre[i] - pre[j]);
}
Rep(i,1,n) dp_before[i] = dp_now[i];
}
int ans = 0;
cout<<dp_now[n];
return 0;
}
int cnt = 0;
Rep(i,1,n) {
cin>>a[i];
if(a[i] < 0) cnt++;
}
if(cnt == 0) {
int sum = 0;
Rep(i,1,n) {
sum += a[i];
}
cout<<sum;
return 0;
}
else {
if(k==1) {
int ans = 0;
Rep(i,1,n) {
dp_now[i] = max(dp_now[i-1] + a[i], a[i]);
ans = max(ans,dp_now[i]);
}
cout<<ans;
}
else {
int sum = 0;
Rep(i,1,n) {
if(a[i]<0) continue;
sum += a[i];
}
cout<<sum;
}
}
}
Compilation message
feast.cpp: In function 'int main()':
feast.cpp:78:7: warning: unused variable 'cek' [-Wunused-variable]
78 | int cek = 0;
| ^~~
feast.cpp:87:7: warning: unused variable 'ans' [-Wunused-variable]
87 | int ans = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5304 KB |
Output is correct |
2 |
Correct |
24 ms |
5392 KB |
Output is correct |
3 |
Correct |
25 ms |
5456 KB |
Output is correct |
4 |
Correct |
25 ms |
5400 KB |
Output is correct |
5 |
Correct |
24 ms |
5452 KB |
Output is correct |
6 |
Correct |
24 ms |
5320 KB |
Output is correct |
7 |
Correct |
24 ms |
5324 KB |
Output is correct |
8 |
Correct |
24 ms |
5436 KB |
Output is correct |
9 |
Correct |
23 ms |
5288 KB |
Output is correct |
10 |
Correct |
23 ms |
5452 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
5980 KB |
Output is correct |
2 |
Correct |
17 ms |
6044 KB |
Output is correct |
3 |
Correct |
17 ms |
5912 KB |
Output is correct |
4 |
Correct |
22 ms |
3668 KB |
Output is correct |
5 |
Correct |
26 ms |
7568 KB |
Output is correct |
6 |
Correct |
17 ms |
5920 KB |
Output is correct |
7 |
Correct |
16 ms |
3740 KB |
Output is correct |
8 |
Correct |
25 ms |
7756 KB |
Output is correct |
9 |
Correct |
25 ms |
7552 KB |
Output is correct |
10 |
Correct |
16 ms |
3696 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
31 ms |
7664 KB |
Output is correct |
2 |
Correct |
28 ms |
7888 KB |
Output is correct |
3 |
Correct |
29 ms |
7920 KB |
Output is correct |
4 |
Correct |
27 ms |
7832 KB |
Output is correct |
5 |
Correct |
27 ms |
7948 KB |
Output is correct |
6 |
Correct |
28 ms |
7884 KB |
Output is correct |
7 |
Correct |
27 ms |
8008 KB |
Output is correct |
8 |
Correct |
28 ms |
7896 KB |
Output is correct |
9 |
Correct |
28 ms |
8016 KB |
Output is correct |
10 |
Correct |
27 ms |
7976 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
0 ms |
336 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
2 ms |
340 KB |
Output is correct |
12 |
Correct |
3 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
2 ms |
340 KB |
Output is correct |
15 |
Correct |
2 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
3 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
348 ms |
420 KB |
Output is correct |
22 |
Execution timed out |
1062 ms |
340 KB |
Time limit exceeded |
23 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
24 ms |
5304 KB |
Output is correct |
2 |
Correct |
24 ms |
5392 KB |
Output is correct |
3 |
Correct |
25 ms |
5456 KB |
Output is correct |
4 |
Correct |
25 ms |
5400 KB |
Output is correct |
5 |
Correct |
24 ms |
5452 KB |
Output is correct |
6 |
Correct |
24 ms |
5320 KB |
Output is correct |
7 |
Correct |
24 ms |
5324 KB |
Output is correct |
8 |
Correct |
24 ms |
5436 KB |
Output is correct |
9 |
Correct |
23 ms |
5288 KB |
Output is correct |
10 |
Correct |
23 ms |
5452 KB |
Output is correct |
11 |
Correct |
21 ms |
5980 KB |
Output is correct |
12 |
Correct |
17 ms |
6044 KB |
Output is correct |
13 |
Correct |
17 ms |
5912 KB |
Output is correct |
14 |
Correct |
22 ms |
3668 KB |
Output is correct |
15 |
Correct |
26 ms |
7568 KB |
Output is correct |
16 |
Correct |
17 ms |
5920 KB |
Output is correct |
17 |
Correct |
16 ms |
3740 KB |
Output is correct |
18 |
Correct |
25 ms |
7756 KB |
Output is correct |
19 |
Correct |
25 ms |
7552 KB |
Output is correct |
20 |
Correct |
16 ms |
3696 KB |
Output is correct |
21 |
Correct |
31 ms |
7664 KB |
Output is correct |
22 |
Correct |
28 ms |
7888 KB |
Output is correct |
23 |
Correct |
29 ms |
7920 KB |
Output is correct |
24 |
Correct |
27 ms |
7832 KB |
Output is correct |
25 |
Correct |
27 ms |
7948 KB |
Output is correct |
26 |
Correct |
28 ms |
7884 KB |
Output is correct |
27 |
Correct |
27 ms |
8008 KB |
Output is correct |
28 |
Correct |
28 ms |
7896 KB |
Output is correct |
29 |
Correct |
28 ms |
8016 KB |
Output is correct |
30 |
Correct |
27 ms |
7976 KB |
Output is correct |
31 |
Correct |
1 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 |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
340 KB |
Output is correct |
42 |
Correct |
3 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
2 ms |
340 KB |
Output is correct |
45 |
Correct |
2 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
3 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
348 ms |
420 KB |
Output is correct |
52 |
Execution timed out |
1062 ms |
340 KB |
Time limit exceeded |
53 |
Halted |
0 ms |
0 KB |
- |