답안 #198513

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
198513 2020-01-26T12:47:07 Z quocnguyen1012 Holding (COCI20_holding) C++14
22 / 110
9 ms 4472 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;

template<class T> inline bool chkmin(T & a, const T & val) {return val < a ? a = val, 1 : 0;}
template<class T> inline bool chkmax(T & a, const T & val) {return a < val ? a = val, 1 : 0;}

const int maxn = 105;

int fl[maxn][maxn][2505], fr[maxn][maxn][2505];
int N, L, R, K, a[maxn];
int sum[maxn];

signed main(void)
{
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  if (fopen("A.INP", "r")){
    freopen("A.INP", "r", stdin);
    freopen("A.OUT", "w", stdout);
  }
  cin >> N >> L >> R >> K;
  K = min(K, N * N / 4);
  for (int i = 1; i <= N; ++i){
    cin >> a[i];
    sum[i] = sum[i - 1] + a[i];
  }
  for (int i = L - 1; i >= 1; --i){
    for (int j = L; j <= R; ++j){
      for (int cost = 0; cost <= K; ++cost){
        chkmax(fl[i][j][cost], fl[i + 1][j][cost]);
        chkmax(fr[i][j][cost], fl[i][j - 1][cost]);
        if (j - i <= cost) chkmax(fl[i][j][cost], fl[i + 1][j - 1][cost - (j - i)] + a[j] - a[i]);
      }
    }
  }
  for (int i = R + 1; i <= N; ++i){
    for (int j = R; j >= L; --j){
      for (int cost = 0; cost <= K; ++cost){
        chkmax(fr[i][j][cost], fr[i - 1][j][cost]);
        chkmax(fr[i][j][cost], fr[i][j + 1][cost]);
        if (i - j <= cost) chkmax(fr[i][j][cost], fr[i - 1][j + 1][cost - (i - j)] + a[j] - a[i]);
      }
    }
  }
  int ret = 0;
  for (int i = L - 1; i <= R; ++i){
    for (int cost = 0; cost <= K; ++cost){
      chkmax(ret, fl[1][i][cost] + fr[N][i + 1][K - cost]);
    }
  }
  cout << sum[R] - sum[L - 1] - ret << '\n';
}

Compilation message

holding.cpp: In function 'int main()':
holding.cpp:24:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.INP", "r", stdin);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
holding.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
     freopen("A.OUT", "w", stdout);
     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 424 KB Output is correct
7 Correct 6 ms 632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 424 KB Output is correct
7 Correct 6 ms 632 KB Output is correct
8 Incorrect 9 ms 4472 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 424 KB Output is correct
7 Correct 6 ms 632 KB Output is correct
8 Incorrect 9 ms 4472 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 504 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 6 ms 376 KB Output is correct
6 Correct 5 ms 424 KB Output is correct
7 Correct 6 ms 632 KB Output is correct
8 Incorrect 9 ms 4472 KB Output isn't correct
9 Halted 0 ms 0 KB -