답안 #833319

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
833319 2023-08-22T04:30:48 Z veehj Feast (NOI19_feast) C++17
59 / 100
261 ms 262144 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
int n, k;
vector<ll> a = {};

void s(){
    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(k+1, vector<ll>(2, -1e15)));
    ll ans=0;
    dp[0][0][1]=0; dp[0][0][0]=0;
    for(int i=1; i<=n; i++){
        dp[i][0][0]=0;
        for(int j=1; j<=k; j++){    
            dp[i][j][0]=max(dp[i-1][j][1], dp[i-1][j][0]);
            dp[i][j][1]=max(dp[i-1][j][1], dp[i-1][j-1][0])+a[i-1];
            // cout << i << ' ' << j << ' ' << dp[i][j][0] << ' ' << dp[i][j][1] << endl;
			ans=max({ans,dp[i][j][0],dp[i][j][1]});
        }
    }
    cout << ans << endl;
}

void f() {
  ll ans = 0, nw = 0;
  for (auto& u : a) {
    nw = max(0LL, nw + u);
    ans = max(ans, nw);
  }
  cout << ans << endl;
  return;
}

int main() {
  cin >> n >> k;
  for (int i = 0; i < n; i++) {
    ll x;
    cin >> x;
    a.pb(x);
  }
  if (k == 1) {
    f();
    return 0;
  }
  s();
}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 261 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 4504 KB Output is correct
2 Correct 45 ms 4412 KB Output is correct
3 Correct 43 ms 4412 KB Output is correct
4 Runtime error 225 ms 262144 KB Execution killed with signal 9
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 87 ms 4412 KB Output is correct
2 Correct 94 ms 4656 KB Output is correct
3 Correct 97 ms 4516 KB Output is correct
4 Correct 93 ms 4504 KB Output is correct
5 Correct 88 ms 4428 KB Output is correct
6 Correct 89 ms 4496 KB Output is correct
7 Correct 88 ms 4512 KB Output is correct
8 Correct 94 ms 4732 KB Output is correct
9 Correct 89 ms 4460 KB Output is correct
10 Correct 89 ms 4404 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 0 ms 340 KB Output is correct
8 Correct 0 ms 212 KB Output is correct
9 Correct 0 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 980 KB Output is correct
12 Correct 1 ms 1236 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 2 ms 980 KB Output is correct
15 Correct 1 ms 724 KB Output is correct
16 Correct 1 ms 596 KB Output is correct
17 Correct 1 ms 1108 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
19 Correct 1 ms 468 KB Output is correct
20 Correct 0 ms 340 KB Output is correct
21 Correct 23 ms 21716 KB Output is correct
22 Correct 174 ms 179264 KB Output is correct
23 Correct 41 ms 41548 KB Output is correct
24 Correct 25 ms 23528 KB Output is correct
25 Correct 34 ms 32468 KB Output is correct
26 Correct 20 ms 19388 KB Output is correct
27 Correct 31 ms 30548 KB Output is correct
28 Correct 4 ms 3924 KB Output is correct
29 Correct 4 ms 3540 KB Output is correct
30 Correct 1 ms 724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 261 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -