답안 #477467

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477467 2021-10-02T08:53:27 Z Neos Holding (COCI20_holding) C++14
0 / 110
9 ms 19224 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<ll, ll> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vii> vvii;
 
#define task "test"
#define fastIO ios::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define forw(i, l, r) for( ll i = (l) ; i < (r) ; i++ )
#define forb(i, r, l) for( ll i = (r) ; i >= (l) ; i-- )
#define sz(x) (int)x.size()
#define fi first
#define se second
#define all(x) x.begin(), x.end()
#define numBit(x) __builtin_popcount(x)
#define lb lower_bound
#define ub upper_bound
#define ar array
#define endl '\n'
 
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
 
const int N = 22;
const ll inf = 0x3f3f3f3f;

int n, l, r, k;
ll a[N];
int dp[N][N][10000];

int solve(int i, int j, int left) {
  int &ret = dp[i][j][left];
  if (ret != -1) return ret;
  if (i >= j || j > r || i >= l) return 0;
  if (j - i <= left)
    ret = solve(i + 1, j + 1, left - (j - i)) + (a[j] - a[i]);
  ret = max(ret, solve(i + 1, j, left));
  ret = max(ret, solve(i, j + 1, left));
  ret = max(ret, solve(i + 1, j + 1, left));
  return ret;
}

int main() {
#ifndef ONLINE_JUDGE
  freopen(task".inp", "r", stdin);
  freopen(task".out", "w", stdout);
#endif
  // fastIO;

  scanf("%d %d %d %d", &n, &l, &r, &k);
  --l, --r;

  ll sum = 0;
  memset(dp, -1, sizeof dp);
  forw(i, 0, n) {
    scanf("%lld", &a[i]);
    if (i >= l && i <= r) sum += a[i];
  }

  printf("%lld", sum - solve(0, l, k));
}

Compilation message

holding.cpp: In function 'int main()':
holding.cpp:54:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:55:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   55 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |   scanf("%d %d %d %d", &n, &l, &r, &k);
      |   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
holding.cpp:65:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   65 |     scanf("%lld", &a[i]);
      |     ~~~~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19224 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 19224 KB Output isn't correct
2 Halted 0 ms 0 KB -