Submission #501844

#TimeUsernameProblemLanguageResultExecution timeMemory
501844reo111K blocks (IZhO14_blocks)C++17
53 / 100
1095 ms844 KiB
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3") //Ofast, avx, avx2, fma //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") //#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native") #include <bits/stdc++.h> /*#include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace __gnu_pbds;*/ #define F first #define S second #define mp make_pair #define pb push_back #define sz(a) int(a.size()) #define all(a) a.begin(), a.end() #define bpc(a) __builtin_popcount(a) #define bpcll(a) __builtin_popcountll(a) #define wtc(a) cerr << (#a) << " = " << a << '\n' #define setprec(a) cout.precision(a) #define base ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #define file(a) freopen(a".in", "r", stdin); freopen(a".out", "w", stdout); #define GET4_(a, b, c, d, ...) d #define FOR_(i, a, b) for (int i = a; i < b; ++i) #define FOR1(a) FOR_(i, 0, a) #define FOR2(i, a) FOR_(i, 0, a) #define FOR3(i, a, b) FOR_(i, a, b) #define FORC_(...) GET4_(__VA_ARGS__, FOR3, FOR2, FOR1) #define FOR(...) FORC_(__VA_ARGS__)(__VA_ARGS__) #define TRV(i, a) for(auto &i : a) using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; typedef vector<int> vi; typedef vector<ll> vll; typedef vector<pii> vpi; typedef vector<pll> vpl; template <class T> using VC = vector<T>; template <class T, class V> using PR = pair<T, V>; //template <class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>; //insert(), find_by_order(), order_of_key(), find(), erase(find())*/ template <class T> bool mns(T &a, T b) {return (a > b ? a = b, 1 : 0);} template <class T> bool mxs(T &a, T b) {return (a < b ? a = b, 1 : 0);} pii DR[] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}, {1, 1}, {1, -1}, {-1, 1}, {-1, -1}}; const int INF = 1e9 + 1e7 + 7; const int MOD = 1e9 + 7;//998244353;//1e9 + 7; const ll INFLL = 1e18 + 1e16 + 7ll; const int N = 1e6 + 5; const int SS = 5e5 + 5; //rank const int cs = 850; void Main(); void precalc(); int main() { base//d //precalc(); //setprec(10); int T = 1; //cin >> T; FOR(i, 1, T + 1) { //cout << "Case #" << i << ": "; Main(); } return 0; } int n, k, a[N], lg[N], st[N][11], dp[N], pd[N]; int get(int l, int r) { int j = lg[r - l + 1]; //wtc(j); return max(st[l][j], st[r - (1 << j) + 1][j]); } void Main() { scanf("%d%d", &n, &k); FOR(n) { int x; scanf("%d", &x); a[i] = x; } FOR(n) dp[i] = INF; lg[1] = 0; FOR(i, 2, n + 1) lg[i] = lg[i / 2] + 1; FOR(n) st[i][0] = a[i]; FOR(j, 1, 11) for (int i = 0; i + (1 << j) <= n; ++i) st[i][j] = max(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]); FOR(n) pd[i] = get(0, i); FOR(j, 2, k + 1) { FOR(i, j - 1, n) { FOR(l, max(0, j - 2), i) { mns(dp[i], pd[l] + get(l + 1, i)); } } FOR(i, j - 1, n) pd[i] = dp[i], dp[i] = INF; } /*FOR(n) { FOR(j, k + 1) { cout << dp[i][j] << ' '; } cout << endl; }*/ printf("%d", pd[n - 1]); }

Compilation message (stderr)

blocks.cpp: In function 'void Main()':
blocks.cpp:89:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   89 |     scanf("%d%d", &n, &k);
      |     ~~~~~^~~~~~~~~~~~~~~~
blocks.cpp:92:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |         scanf("%d", &x);
      |         ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...