Submission #88040

#TimeUsernameProblemLanguageResultExecution timeMemory
88040vanbang9710Split the sequence (APIO14_sequence)C++14
71 / 100
2077 ms83196 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; inline void Cin(int &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'; } inline void Cout(int x) { if (x > 9) Cout(x / 10); putchar(x % 10 + '0'); } inline void Cout(ll x) { if (x > 9) Cout(x / 10); putchar(x % 10 + '0'); } const int maxN = 1e5, maxK = 200; const int Inf = 2e9; int trace[maxN][maxK], s[maxN], N, K, a; static ll f[maxN], t, q; struct TLine { int x; ll y; int p; } p[maxN]; typedef TLine* PLine; PLine id[maxN]; inline ll Get(const PLine l) { return t * l->x + l->y; } //inline ll Div(ll a, ll b) { return (q = a / b) - ((a ^ b) < 0 && a - b * q); } inline void Intersect(const PLine a, const PLine b) { if (a->x == b->x) a->p = a->y > b->y ? Inf : -Inf; else a->p = (a->y - b->y) / (b->x - a->x); //else a->p = Div(a->y - b->y, b->x - a->x); } 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) { auto nId = id - 1, j = id; ll val = f[k], res, tmp; for (int i = k + 1; i < N; ++i) { --i; auto idi = p + i; *idi = {s[i], val - (ll)s[i] * s[i], Inf}; if (nId >= id) Intersect(*nId, idi); while (nId > id && (*(nId - 1))->p >= (*nId)->p) Intersect(*(--nId), idi); *(++nId) = idi; val = f[++i]; t = s[i]; if (j >= nId) j = nId; else while (j < nId && (*j)->p < t) ++j; f[i] = Get(*j); trace[i][k] = *j - p; } } Cout(f[N - 1]); putchar('\n'); int i = N - 1; while (--K >= 0) Cout((i = trace[i][K]) + 1), putchar(' '); #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:90:24: warning: unused variable 'res' [-Wunused-variable]
         ll val = f[k], res, tmp;
                        ^~~
sequence.cpp:90:29: warning: unused variable 'tmp' [-Wunused-variable]
         ll val = f[k], res, tmp;
                             ^~~
sequence.cpp: At global scope:
sequence.cpp:54:23: warning: 'q' defined but not used [-Wunused-variable]
 static ll f[maxN], t, q;
                       ^
#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...