Submission #955880

#TimeUsernameProblemLanguageResultExecution timeMemory
955880thunoproK blocks (IZhO14_blocks)C++14
53 / 100
3 ms604 KiB
#include<bits/stdc++.h> using namespace std ; #define maxn 109 #define ll long long #define fi first #define se second #define pb push_back #define left id<<1 #define right id<<1|1 #define _lower(x) lower_bound(v.begin(),v.end(),x)-v.begin()+1 #define TIME (1.0*clock()/TIME_PERS_SEC) #define re exit(0); const int mod = 1e9+7 ; const int INF = 1e9 ; typedef vector<int> vi ; typedef pair<int,int> pii ; typedef vector<pii> vii ; void add ( int &a , int b ) { a += b ; if ( a >= mod ) a -= mod ; if ( a < 0 ) a += mod ; } template < typename T > void chkmin ( T &a , T b ) { if ( a > b ) a = b ;} template < typename T > void chkmax ( T &a , T b ) { if ( a < b ) a = b ;} void rf () { freopen ("bai1.inp","r",stdin) ; } mt19937 rng (time(0)) ; int _pow ( int a , int n ) { if ( n == 0 ) return 1 ; int res = _pow (a,n/2) ; if ( n % 2 ) return 1ll*res*res%mod*a%mod ; else return 1ll*res*res%mod ; } int n , k ; int a [maxn] ; int dp [maxn][109] ; int L [maxn][18] ; int get ( int l , int r ) { int x = __lg(r-l+1) ; return max(L[l][x],L[r-(1<<x)+1][x]) ; } int main () { ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0); // rf () ; cin >> n >> k ; for ( int i = 1 ; i <= n ; i ++ ) cin >> a [i] , L [i][0] = a [i] ; for ( int j = 1 ; j <= __lg(n) ; j ++ ) { for ( int i = 1 ; i <= n - (1<<j) + 1 ; i ++ ) { L [i][j] = max (L[i][j-1],L[i+(1<<(j-1))][j-1]) ; } } memset ( dp , 0x3f , sizeof dp ) ; dp [0][0] = 0 ; for ( int t = 1 ; t <= k ; t ++ ) { for ( int i = 1 ; i <= n ; i ++ ) { for ( int j = 1 ; j <= i ; j ++ ) { chkmin (dp[i][t],dp[j-1][t-1]+get(j,i)) ; } } } cout << dp [n][k] ; }

Compilation message (stderr)

blocks.cpp: In function 'void rf()':
blocks.cpp:33:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   33 |  freopen ("bai1.inp","r",stdin) ;
      |  ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...