Submission #241377

#TimeUsernameProblemLanguageResultExecution timeMemory
241377MercenaryK blocks (IZhO14_blocks)C++14
100 / 100
196 ms41832 KiB
#include<bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/trie_policy.hpp> #define pb push_back #define mp make_pair #define taskname "A" using namespace std; using namespace __gnu_pbds; typedef long long ll; typedef long double ld; typedef pair<int,int> ii; typedef tree <int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set; const int maxn = 1e5 + 5; const int maxk = 1e2 + 1; const int logn = log2(maxn) + 1; int dp[101][maxn]; int n , k , a[maxn]; int dp1[maxn]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); if(fopen(taskname".INP","r")){ freopen(taskname".INP", "r",stdin); freopen(taskname".OUT", "w",stdout); } fill_n(&dp[0][0],maxn*maxk,1e9); dp[1][0] = 0; cin >> n >> k; for(int i = 1 ; i <= n ; ++i){ cin >> a[i]; dp[1][i] = max(dp[1][i - 1] , a[i]); } dp[1][0] = 1e9; for(int i = 2 ; i <= k ; ++i){ vector<int> s; for(int j = 1 ; j <= n ; ++j){ int tmp = dp[i - 1][j - 1]; while(s.size() && a[s.back()] <= a[j]){ tmp = min(tmp , dp1[s.back()]); s.pop_back(); } dp1[j] = tmp; dp[i][j] = tmp + a[j]; if(s.size())dp[i][j] = min(dp[i][j] , dp[i][s.back()]); s.pb(j); // cout << dp[i][j] << " "; } } cout << dp[k][n]; }

Compilation message (stderr)

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