답안 #235404

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
235404 2020-05-28T08:36:46 Z doowey Holding (COCI20_holding) C++14
55 / 110
73 ms 7032 KB
#include <bits/stdc++.h>

using namespace std;

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

#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);

const int N = 105;
const int S = N * (N + 1);
const int M = S/2;
const int inf = (int)1e9;

int dp[2][N][S]; // pick i items, indice sum j
int st[N][S];
int ri[N][S];
int a[N];

void upd(int &a, int b){  
  a = min(a, b);
}

int main(){
  fastIO;
  int n, l, r, k;
  cin >> n >> l >> r >> k;
  for(int i = 0 ; i <= n; i ++ ){
    for(int j = 0 ; j < S; j ++ ){
      dp[0][i][j] = dp[1][i][j] = inf;
    }
  }
  dp[0][0][M]=0;
  int ans = 0;
  for(int i = 1; i <= n; i ++ ){
    cin >> a[i];
    if(i >= l && i <= r) ans += a[i];
  }
  for(int i = 1; i <= r; i ++ ){
    for(int j = 0 ; j <= n ; j ++ ){
      for(int x = 0; x < S ; x ++ ){
        if(i < l){
          if(dp[0][j][x] == inf) continue;
          upd(dp[1][j + 1][x - i], dp[0][j][x] + a[i]);
          upd(dp[1][j][x], dp[0][j][x]);
        }
        else{
          if(dp[0][j][x] == inf) continue;
          if(j) upd(dp[1][j - 1][x + i], dp[0][j][x]);
          upd(dp[1][j][x], dp[0][j][x] + a[i]);
        }
      }
    }
    for(int j = 0 ; j <= n ; j ++ ){
      for(int x = 0; x < S; x ++ ){
        dp[0][j][x]=dp[1][j][x];
        dp[1][j][x]=inf;
      }
    }
    for(int x = 0; x < S; x ++ ){
      st[i][x]=dp[0][0][x];
    }
  }
  for(int x = 0; x <= k ; x ++ )
    upd(ans, dp[0][0][x + M]);
  cout << ans << "\n";
  /*
  for(int i = 0 ; i <= n; i ++ ){
    for(int j = 0 ; j < S; j ++ ){
      dp[0][i][j] = dp[1][i][j] = inf;
    }
  }
  */
  /*
  dp[0][0][M]=0;
  for(int i = n; i >= l ; i -- ){
    for(int j = 0 ; j <= n; j ++ ){
      for(int x = 0; x < S; x ++ ){
        if(dp[0][j][x] == inf) continue;
        if(i > r){
          upd(dp[1][j + 1][x + i], dp[0][j][x] + a[i]);
          upd(dp[1][j][x], dp[0][j][x]);
        }
        else{
          if(j) upd(dp[1][j - 1][x - i], dp[0][j][x]);
          upd(dp[1][j][x], dp[0][j][x] + a[i]);
        }
      }
    }
    for(int j = 0 ; j <= n ; j ++ ){
      for(int x = 0; x < S; x ++ ){
        dp[0][j][x]=dp[1][j][x];
        dp[1][j][x]=inf;
      }
    }
    for(int x = 0 ;x < S; x ++ ){
      ri[i][x]=dp[0][0][x];
      if(x)
        upd(ri[i][x],ri[i][x-1]);
    }
  }
  for(int x = 0 ; x <= k ; x ++ ){
    upd(ans, st[r][x + M]);
    //upd(ans, ri[l][x + M]);
  }
  /*
  for(int i = l; i + 1 <= r; i ++ ){
    for(int x = 0; x <= k ; x ++ ){
      upd(ans, st[i][x + M] + ri[i + 1][k - x + M]);
    }
  }
  */
  return 0;
}

Compilation message

holding.cpp:110:3: warning: "/*" within comment [-Wcomment]
   /*
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 10 ms 2176 KB Output is correct
3 Correct 9 ms 2176 KB Output is correct
4 Correct 10 ms 2196 KB Output is correct
5 Correct 10 ms 2176 KB Output is correct
6 Correct 10 ms 2176 KB Output is correct
7 Correct 10 ms 2048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 10 ms 2176 KB Output is correct
3 Correct 9 ms 2176 KB Output is correct
4 Correct 10 ms 2196 KB Output is correct
5 Correct 10 ms 2176 KB Output is correct
6 Correct 10 ms 2176 KB Output is correct
7 Correct 10 ms 2048 KB Output is correct
8 Correct 69 ms 7032 KB Output is correct
9 Correct 72 ms 7032 KB Output is correct
10 Correct 64 ms 7032 KB Output is correct
11 Correct 73 ms 7032 KB Output is correct
12 Correct 72 ms 7032 KB Output is correct
13 Correct 69 ms 6904 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 10 ms 2176 KB Output is correct
3 Correct 9 ms 2176 KB Output is correct
4 Correct 10 ms 2196 KB Output is correct
5 Correct 10 ms 2176 KB Output is correct
6 Correct 10 ms 2176 KB Output is correct
7 Correct 10 ms 2048 KB Output is correct
8 Correct 69 ms 7032 KB Output is correct
9 Correct 72 ms 7032 KB Output is correct
10 Correct 64 ms 7032 KB Output is correct
11 Correct 73 ms 7032 KB Output is correct
12 Correct 72 ms 7032 KB Output is correct
13 Correct 69 ms 6904 KB Output is correct
14 Correct 46 ms 6136 KB Output is correct
15 Correct 66 ms 6776 KB Output is correct
16 Incorrect 38 ms 5888 KB Output isn't correct
17 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1152 KB Output is correct
2 Correct 10 ms 2176 KB Output is correct
3 Correct 9 ms 2176 KB Output is correct
4 Correct 10 ms 2196 KB Output is correct
5 Correct 10 ms 2176 KB Output is correct
6 Correct 10 ms 2176 KB Output is correct
7 Correct 10 ms 2048 KB Output is correct
8 Correct 69 ms 7032 KB Output is correct
9 Correct 72 ms 7032 KB Output is correct
10 Correct 64 ms 7032 KB Output is correct
11 Correct 73 ms 7032 KB Output is correct
12 Correct 72 ms 7032 KB Output is correct
13 Correct 69 ms 6904 KB Output is correct
14 Correct 46 ms 6136 KB Output is correct
15 Correct 66 ms 6776 KB Output is correct
16 Incorrect 38 ms 5888 KB Output isn't correct
17 Halted 0 ms 0 KB -