Submission #246758

#TimeUsernameProblemLanguageResultExecution timeMemory
246758aloo123K blocks (IZhO14_blocks)C++14
0 / 100
1094 ms736 KiB
#include <algorithm> #include <bitset> #include <cassert> #include <chrono> // #include <cgridh> #include <complex> #include <cstdio> #include <cstdlib> #include <cstring> #include <ctime> #include <deque> #include <functional> #include <iomanip> #include <iostream> #include <iterator> #include <limits> #include <list> #include <map> #include <numeric> #include <queue> #include <random> #include <ratio> #include <set> #include <sstream> #include <stack> #include <string> #include <unordered_map> #include <unordered_set> #include <utility> #include <vector> #include <climits> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/assoc_container.hpp> // #include <ext/pb_ds/trie_policy.hpp> #define ll long long #define ld long double #define mp make_pair #define pb push_back #define in insert #define vll vector<ll> #define endl "\n" #define pll pair<ll,ll> #define f first #define s second #define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++) #define int ll #define sz(x) (ll)x.size() #define all(x) (x.begin(),x.end()) using namespace std; // using namespace __gnu_pbds; // typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> os; const ll INF = 1e12; const ll N =(1e5+5); // TODO : change value as per problem const ll MOD = 1e9+7; ll a[N]; int n; ll dp[105][N]; long long C(int i, int j){ ll ma = 0; for(int x = i;x<=j;x++) ma = max(ma,a[x]); return ma; } // compute dp_cur[l], ... dp_cur[r] (inclusive) void compute(int d, int l, int r, int u, int v) { if (l > r) return ; int mid = (l + r) >> 1; dp[d][mid] = INF; int savek = u; FOR(k,u,min(v, mid)) { int now = dp[d-1][k-1] + C(k, mid); if (now < dp[d][mid]) { dp[d][mid] = now; savek = k; } } if(l==r) return; compute(d, l, mid-1, u, savek); compute(d, mid+1, r, savek, v); } void solve(){ ll k; cin >>n>> k; for(int i =1;i<=n;i++) cin >> a[i]; FOR(i,1,n) dp[0][i] = INF; FOR(d,1,k) compute(d,0,n,1,n); // for(int i =1;i<=k;i++){ // for(int j =1;j<=n;j++){ // cout << i << " " << j << ' ' << dp[i][j] << endl; // } // } cout << dp[k][n] << endl; } signed main(){ ios_base::sync_with_stdio(0); cin.tie(NULL); ll tt=1; // cin >> tt; while(tt--){ solve(); } }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...