Submission #1312598

#TimeUsernameProblemLanguageResultExecution timeMemory
1312598zangdoK개의 묶음 (IZhO14_blocks)C++20
0 / 100
1 ms568 KiB
/****************************************************************************** Online C++ Compiler. Code, Compile, Run and Debug C++ program online. Write your code in this editor and press "Run" button to compile and execute it. *******************************************************************************/ #include <bits/stdc++.h> using namespace std; const int MAXN = 1e5 +5; const int MAXK = 105; int arr[MAXN] ,pos[MAXN],n,k; long long dp[MAXN][MAXK], pref[MAXN]; stack <int> gay; int main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); freopen("blocks.in", "r", stdin); freopen("blocks.out", "w", stdout); cin>>n>>k; for(int i=1; i<=n;i++) {cin>>arr[i]; pref[i]=pref[i-1]+arr[i];} for(int i=n; i>=1; i--){ while(!gay.empty()){ if(arr[i]>arr[gay.top()]) {pos[gay.top()]= i;gay.pop();} else break; } gay.push(i); } int maxt=-1; for(int i=1 ;i<=n;i++){ maxt=max(maxt, arr[i]); dp[i][1]=maxt; } for (int i=1; i<=n;i++){ for(int j=2; j<=k;j++){ if(i<j) break; if(pos[i]<j-1) dp[i][j]= pref[j-1]+arr[i]; else dp[i][j]= min(dp[pos[i]][j-1] + arr[i],dp[pos[i]][j]); } } //cout<<arr[1]<<endl; cout<<dp[n][k]; return 0; }

Compilation message (stderr)

blocks.cpp: In function 'int main()':
blocks.cpp:21:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     freopen("blocks.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
blocks.cpp:22:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |     freopen("blocks.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...