Submission #330404

# Submission time Handle Problem Language Result Execution time Memory
330404 2020-11-25T06:24:18 Z 534351 Holding (COCI20_holding) C++17
110 / 110
167 ms 4900 KB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

const int INF = 1e9 + 7;
const int MAXN = 113;

int N, L, R, K;
int arr[MAXN];
int dp[2][MAXN][MAXN * MAXN];
int ans;

int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> L >> R >> K; L--; R--;
    FOR(i, 0, N)
    {
        cin >> arr[i];
    }
    FOR(j, 0, R - L + 2)
    {
        FOR(k, 0, K + 1)
        {
            dp[1][j][k] = INF;
        }
    }
    dp[1][0][0] = 0;
    FOR(i, 0, N) //dp[pos][# numbers selected][# moves]
    {
        FOR(j, 0, R - L + 2)
        {
            FOR(k, 0, K + 1)
            {
                dp[0][j][k] = dp[1][j][k];
                dp[1][j][k] = INF;
            }
        }
        FOR(j, 0, R - L + 2)
        {
            FOR(k, 0, K + 1)
            {
                //select another number.
                ckmin(dp[1][j + 1][k + abs(i - (L + j))], dp[0][j][k] + arr[i]);
                //don't select another number.
                ckmin(dp[1][j][k], dp[0][j][k]);
            }
        }
    }
    ans = INF;
    FOR(k, 0, K + 1)
    {
        ckmin(ans, dp[1][R - L + 1][k]);
    }
    cout << ans << '\n';
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 6 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 6 ms 1004 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 43 ms 2720 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 6 ms 1004 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 43 ms 2720 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 45 ms 2748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 492 KB Output is correct
5 Correct 1 ms 492 KB Output is correct
6 Correct 1 ms 492 KB Output is correct
7 Correct 6 ms 1004 KB Output is correct
8 Correct 1 ms 492 KB Output is correct
9 Correct 1 ms 512 KB Output is correct
10 Correct 1 ms 620 KB Output is correct
11 Correct 2 ms 620 KB Output is correct
12 Correct 1 ms 748 KB Output is correct
13 Correct 43 ms 2720 KB Output is correct
14 Correct 1 ms 364 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 364 KB Output is correct
17 Correct 1 ms 364 KB Output is correct
18 Correct 1 ms 492 KB Output is correct
19 Correct 45 ms 2748 KB Output is correct
20 Correct 2 ms 492 KB Output is correct
21 Correct 2 ms 364 KB Output is correct
22 Correct 1 ms 492 KB Output is correct
23 Correct 4 ms 492 KB Output is correct
24 Correct 8 ms 1004 KB Output is correct
25 Correct 167 ms 4900 KB Output is correct