Submission #1125634

#TimeUsernameProblemLanguageResultExecution timeMemory
1125634baoheyheyK blocks (IZhO14_blocks)C++17
0 / 100
26 ms41544 KiB
#include<bits/stdc++.h> #define ll long long #define FOR(i, l, r) for(int i = (l), _r = r; i <= _r; ++i) #define FOD(i, l, r) for(int i = (l), _r = r; i >= _r; --i) #define pb push_back #define ALL(a) a.begin(), a.end() #define el "\n" #define bit(a, x) (a >> x & 1) #define X first #define Y second #define TIME (1.0 * clock() / CLOCKS_PER_SEC) #define cntbit(x) __builtin_popcountll(x) #define uni(a) sort(ALL(a)), a.resize(unique(ALL(a)) - a.begin()) #define sz(a) a.size() using namespace std; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; const int maxn = 1e5 + 5; int dp[maxn][105]; int n, a[maxn], k; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); #define task "task" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } cin >> n >> k; FOR(i, 1, n) cin >> a[i]; memset(dp, 0x3f, sizeof(dp)); dp[0][1] = 0; FOR(i, 1, n) dp[i][1] = max(dp[i - 1][1], a[i]); FOR(i, 2, k){ stack<pii> st; FOR(j, i, n){ int minn = dp[j - 1][i - 1]; while(sz(st) && a[st.top().Y] <= a[j]){ minn = st.top().X; st.pop(); } dp[j][i] = min(dp[(sz(st) ? st.top().Y : 0)][i], minn + a[j]); st.push({minn, j}); } } cout << dp[n][k]; cerr << "Time elapsed: " << TIME << " s" << el; }

Compilation message (stderr)

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