Submission #563249

# Submission time Handle Problem Language Result Execution time Memory
563249 2022-05-16T15:04:35 Z tamthegod K blocks (IZhO14_blocks) C++14
0 / 100
33 ms 79332 KB
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<string.h>
#include<cmath>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<unordered_set>
#include<cstdio>
#include<bitset>
#include<chrono>
#include<random>
#include<ext/rope>
/* ordered_set
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
*/
#define int long long
#define pb push_back
#define fi first
#define se second
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxN = 1e5 + 5;
const int maxK = 1e2 + 1;
const int mod = 1e9 + 7;
const ll oo = 1e18;
int n, k, a[maxN];
int f[maxN][maxK];
void ReadInput()
{
    cin >> n >> k;
    for(int i=1; i<=n; i++) cin >> a[i];
}
void Solve()
{
    memset(f, 3, sizeof f);
    f[0][0] = 0;
    for(int i=1; i<=n; i++)
    {
        int _max = 0;
        for(int j=1; j<=k; j++)
        {
            f[i][j] = f[i - 1][j - 1] + a[i];
            int _max = 0;
            for(int t=i; t>=1; t--)
            {
                _max = max(_max, a[t]);
                if(a[i] > a[t]) f[i][j] = min(f[i][j], f[t - 1][j - 1] + _max);
            }
        }
    }
    cout << f[n][k];
}
int32_t main()
{
    // freopen("x.inp", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}

Compilation message

blocks.cpp: In function 'void Solve()':
blocks.cpp:51:13: warning: unused variable '_max' [-Wunused-variable]
   51 |         int _max = 0;
      |             ^~~~
# Verdict Execution time Memory Grader output
1 Correct 33 ms 79332 KB Output is correct
2 Incorrect 31 ms 79316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 79248 KB Output is correct
2 Incorrect 32 ms 79256 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 79332 KB Output is correct
2 Incorrect 31 ms 79316 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 33 ms 79332 KB Output is correct
2 Incorrect 31 ms 79316 KB Output isn't correct
3 Halted 0 ms 0 KB -