Submission #1040440

#TimeUsernameProblemLanguageResultExecution timeMemory
1040440Neco_arcK blocks (IZhO14_blocks)C++17
0 / 100
1 ms2652 KiB
#include <bits/stdc++.h> #ifdef LOCAL #include <bits/debug.hpp> #endif // LOCAL #define ll long long #define all(x) x.begin(), x.end() #define Neco "K blocks" #define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin()) #define getbit(x,i) ((x >> i)&1) #define _left id * 2, l, mid #define _right id * 2 + 1, mid + 1, r #define cntbit(x) __builtin_popcountll(x) #define fi(i, a, b) for(int i = a; i <= b; i++) #define fid(i, a, b) for(int i = a; i >= b; i--) #define maxn (int) 1e5 + 7 using namespace std; const ll mod = 1e9 + 7; //972663749 const ll base = 911382323; int n, k; int a[maxn]; pair<int, ll> q[maxn]; ll dp[2][maxn]; void solve() { cin >> n >> k; fi(i, 1, n) cin >> a[i]; int pre = 0, cur = 1; memset(dp, 60, sizeof dp); dp[0][0] = 0; fi(t, 1, k) { int top = 0; fi(i, 1, n) { ll Min = dp[pre][i - 1]; while(top && a[i] >= a[q[top].first]) { Min = min(q[top].second, Min); --top; } dp[cur][i] = Min + a[i]; if(top) dp[cur][i] = min(dp[cur][i], dp[cur][q[top].first]); q[++top] = {i, Min}; } swap(pre, cur); } cout << dp[pre][n]; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); if(fopen(Neco".inp", "r")) { freopen(Neco".inp", "r", stdin); freopen(Neco".out", "w", stdout); } int nTest = 1; // cin >> nTest; while(nTest--) { solve(); } return 0; }

Compilation message (stderr)

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