답안 #246758

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
246758 2020-07-10T06:37:52 Z aloo123 K개의 묶음 (IZhO14_blocks) C++14
0 / 100
1000 ms 736 KB
#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();
    }    
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 4 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Incorrect 4 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 4 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Incorrect 5 ms 384 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 5 ms 640 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 1094 ms 736 KB Time limit exceeded
2 Halted 0 ms 0 KB -