Submission #88031

#TimeUsernameProblemLanguageResultExecution timeMemory
88031vanbang9710Split the sequence (APIO14_sequence)C++14
71 / 100
2078 ms82320 KiB
#include<iostream> #include<ctime> #include<cstdlib> #include<cstdio> #include<cmath> #include<climits> #include<cstring> #include<iomanip> #include<string> #include<bitset> #include<unordered_map> #include<unordered_set> #include<set> #include<vector> #include<map> #include<queue> #include<stack> #include<deque> #include<algorithm> #include<functional> #include<chrono> //#include<windows.h> //#include<direct.h> #include<random> #include<sstream> #define y0 asdahsdlkahsdad #define y1 aasdfasdfasdf #define yn askfhwqriuperikldjk #define j1 assdgsdgasghsf #define taskname "sequence" //#define GuiltiaSinJurai typedef long long ll; typedef unsigned long long ull; typedef long double ld; using namespace std; template <typename T> inline void Cin(T &x) { register char c; for (c = getchar(); c < '0' || c > '9'; c = getchar()); for (x = 0; c >= '0' && c <= '9'; c = getchar()) x = x * 10 + c - '0'; } const int maxN = 1e5, maxK = 200; int trace[maxN][maxK], s[maxN], nId, N, K, a; static ll f[maxN]; struct TLine { int x; ll y; } p[maxN]; typedef TLine* PLine; PLine id[maxN]; inline bool Erase(const PLine a, const PLine b, const PLine c) { return (a->y - c->y) * (b->x - c->x) <= (c->x - a->x) * (c->y - b->y); } int main() { #ifdef GuiltiaSinJurai auto start = chrono::steady_clock::now(); #endif ios_base::sync_with_stdio(0); cin.tie(0); //freopen(taskname".inp", "r", stdin); //freopen(taskname".out", "w", stdout); Cin(N); Cin(K); for (int i = 0, val = 0; i < N; ++i) Cin(a), s[i] = (val += a); for (int k = 0; k < K; ++k) { nId = -1; int j = 0; ll val = f[k], res, tmp; for (int i = k + 1; i < N; ++i) { --i; p[i] = {s[i], val - (ll)s[i] * s[i]}; auto idi = p + i; while (nId >= 1 && Erase(id[nId - 1], id[nId], idi)) --nId; id[++nId] = idi; val = f[++i]; int t = s[i]; #define Get(l) ((ll)t * l->x + l->y) if (j >= nId) res = Get(id[j = nId]); else for (res = Get(id[j]); j < nId; ++j) if (res < (tmp = Get(id[j + 1]))) res = tmp; else break; f[i] = res; trace[i][k] = id[j] - p; } } cout << f[N - 1] << '\n'; int i = N - 1; while (--K >= 0) cout << (i = trace[i][K]) + 1 << ' '; #ifdef GuiltiaSinJurai auto end = chrono::steady_clock::now(); cerr << "In milliseconds : " << chrono::duration_cast<chrono::milliseconds>(end - start).count(); cerr << '\n' << "In seconds : " << chrono::duration_cast<chrono::seconds>(end - start).count() << '\n'; #endif return 0; }

Compilation message (stderr)

sequence.cpp: In function 'int main()':
sequence.cpp:94:42: warning: operation on 'j' may be undefined [-Wsequence-point]
             if (j >= nId) res = Get(id[j = nId]);
                                        ~~^~~
sequence.cpp:93:37: note: in definition of macro 'Get'
             #define Get(l) ((ll)t * l->x + l->y)
                                     ^
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...