답안 #235495

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
235495 2020-05-28T11:26:05 Z doowey Holding (COCI20_holding) C++14
88 / 110
223 ms 262148 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 = 102;
const int S = N * (N + 1);
const int M = S/2;
const int inf = (int)1e9;

int dpL[N][N][S]; // pick i items, indice sum j
int dpR[N][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 q = 0; q <= n + 1; q ++ ){
    for(int d = 0; d <= n; d ++ ){
      for(int s = 0; s < S; s ++ ){
        dpL[q][d][s] = inf;
        dpR[q][d][s] = inf;
      }
    }
  }
  dpL[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(dpL[i-1][j][x] == inf) continue;
          dpL[i][j + 1][x - i] = min(dpL[i][j + 1][x - i], dpL[i-1][j][x] + a[i]);
          dpL[i][j][x] = min(dpL[i][j][x], dpL[i-1][j][x]);
        }
        else{
          if(dpL[i-1][j][x] == inf) continue;
          if(j) dpL[i][j - 1][x + i] = min(dpL[i][j - 1][x + i], dpL[i-1][j][x]);
          dpL[i][j][x] = min(dpL[i][j][x], dpL[i-1][j][x] + a[i]);
        }
      }
    }
  }
  for(int x = 0; x <= k ; x ++ ){
    ans = min(ans, dpL[r][0][x + M]);
  }
  dpR[n + 1][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(dpR[i + 1][j][x] == inf) continue;
        if(i > r){
          dpR[i][j + 1][x + i] =min(dpR[i][j + 1][x + i], dpR[i + 1][j][x] + a[i]);
          dpR[i][j][x] = min(dpR[i][j][x], dpR[i + 1][j][x]);
        }
        else{
          if(j) dpR[i][j - 1][x - i] = min(dpR[i][j - 1][x - i], dpR[i + 1][j][x]);
          dpR[i][j][x] = min(dpR[i][j][x], dpR[i + 1][j][x] + a[i]);
        }
      }
    }
  }
  for(int x = 0; x <= k ; x ++ ){
    ans = min(ans, dpR[l][0][x + M]);
  }
  for(int i = l ; i + 1 <= r; i ++ ){
    for(int x = 0; x <= k; x ++ ){
      if(dpL[i][0][x + M] == inf) continue;
      for(int y = 0; x + y <= k; y ++ ){
        if(dpR[i + 1][0][y + M] == inf) continue;
        ans = min(ans, dpL[i][0][x + M] + dpR[i + 1][0][y + M]);
      }
    }
  }
  cout << ans << "\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3840 KB Output is correct
2 Correct 17 ms 17920 KB Output is correct
3 Correct 17 ms 17920 KB Output is correct
4 Correct 17 ms 17920 KB Output is correct
5 Correct 18 ms 17920 KB Output is correct
6 Correct 17 ms 17920 KB Output is correct
7 Correct 23 ms 15736 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3840 KB Output is correct
2 Correct 17 ms 17920 KB Output is correct
3 Correct 17 ms 17920 KB Output is correct
4 Correct 17 ms 17920 KB Output is correct
5 Correct 18 ms 17920 KB Output is correct
6 Correct 17 ms 17920 KB Output is correct
7 Correct 23 ms 15736 KB Output is correct
8 Correct 157 ms 219288 KB Output is correct
9 Correct 161 ms 219256 KB Output is correct
10 Correct 160 ms 219384 KB Output is correct
11 Correct 158 ms 219384 KB Output is correct
12 Correct 171 ms 219300 KB Output is correct
13 Correct 221 ms 219256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3840 KB Output is correct
2 Correct 17 ms 17920 KB Output is correct
3 Correct 17 ms 17920 KB Output is correct
4 Correct 17 ms 17920 KB Output is correct
5 Correct 18 ms 17920 KB Output is correct
6 Correct 17 ms 17920 KB Output is correct
7 Correct 23 ms 15736 KB Output is correct
8 Correct 157 ms 219288 KB Output is correct
9 Correct 161 ms 219256 KB Output is correct
10 Correct 160 ms 219384 KB Output is correct
11 Correct 158 ms 219384 KB Output is correct
12 Correct 171 ms 219300 KB Output is correct
13 Correct 221 ms 219256 KB Output is correct
14 Correct 146 ms 219384 KB Output is correct
15 Correct 151 ms 219384 KB Output is correct
16 Correct 148 ms 219256 KB Output is correct
17 Correct 149 ms 219360 KB Output is correct
18 Correct 155 ms 219256 KB Output is correct
19 Correct 223 ms 219384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 3840 KB Output is correct
2 Correct 17 ms 17920 KB Output is correct
3 Correct 17 ms 17920 KB Output is correct
4 Correct 17 ms 17920 KB Output is correct
5 Correct 18 ms 17920 KB Output is correct
6 Correct 17 ms 17920 KB Output is correct
7 Correct 23 ms 15736 KB Output is correct
8 Correct 157 ms 219288 KB Output is correct
9 Correct 161 ms 219256 KB Output is correct
10 Correct 160 ms 219384 KB Output is correct
11 Correct 158 ms 219384 KB Output is correct
12 Correct 171 ms 219300 KB Output is correct
13 Correct 221 ms 219256 KB Output is correct
14 Correct 146 ms 219384 KB Output is correct
15 Correct 151 ms 219384 KB Output is correct
16 Correct 148 ms 219256 KB Output is correct
17 Correct 149 ms 219360 KB Output is correct
18 Correct 155 ms 219256 KB Output is correct
19 Correct 223 ms 219384 KB Output is correct
20 Runtime error 153 ms 262148 KB Execution killed with signal 9 (could be triggered by violating memory limits)
21 Halted 0 ms 0 KB -