Submission #1101404

#TimeUsernameProblemLanguageResultExecution timeMemory
1101404quocthangK blocks (IZhO14_blocks)C++14
53 / 100
16 ms17024 KiB
#include <bits/stdc++.h> #define base 31 #define fi first #define endl "\n" #define se second #define NAME "FILE" #define ll long long //#define int long long #define mod 1000000007 #define pii pair<int,int> #define bit(mask,i) (mask&(1<<i)) #define lcm(a,b) ((a*b)/__gcd(a,b)) #define turn_on(mask,i) (mask|(1<<i)) #define turn_off(mask,i) (mask^(1<<i)) template <class T1, class T2> bool maximize(T1 &a, T2 b){if (a < b){a = b; return 1;} return 0;} template <class T1, class T2> bool minimize(T1 &a, T2 b){if (a > b){a = b; return 1;} return 0;} template <class T1, class T2> void add(T1 &a, T2 b){a += b; if (a >= mod) a -= mod;} template <class T1, class T2> void sub(T1 &a, T2 b){a -= b; if (a < 0) a += mod;} using namespace std; int n,k,dp[1010][1010],a[100010]; int mx[100010][20]; int get(int l,int r){ int k=__lg(r-l+1); return max(mx[l][k],mx[r-(1<<k)+1][k]); } signed main(){ ios_base::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL); if (fopen(NAME".inp","r")){ freopen(NAME".inp","r",stdin); freopen(NAME".out","w",stdout); } cin>>n>>k; for(int i=1;i<=n;i++)cin>>a[i],mx[i][0]=a[i]; for(int j=1;(1<<j)<=n;j++){ for(int i=1;i+(1<<j)-1<=n;i++){ mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]); } } memset(dp,0x3f,sizeof dp); dp[0][0]=0; for(int j=1;j<=k;j++){ for(int i=1;i<=n;i++){ for(int k=1;k<=i;k++){ minimize(dp[i][j],dp[k-1][j-1]+get(k,i)); } } } cout<<dp[n][k]; }

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:39:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |   freopen(NAME".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:40:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   40 |   freopen(NAME".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...