Submission #89290

# Submission time Handle Problem Language Result Execution time Memory
89290 2018-12-11T12:19:50 Z vanbang9710 Split the sequence (APIO14_sequence) C++17
71 / 100
2000 ms 83660 KB
#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;
 
int trace[maxN][maxK], s[maxN], N, K, a;
static ll f[maxN], t;
 
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);
}
inline ll Get(const PLine l) { return t * l->x + l->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)
    {
        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]};
            auto lim = max(id + 1, j);
            while (nId >= lim && Erase(*(nId - 1), *nId, idi)) --nId;
            *(++nId) = idi;
            val = f[++i];
            t = s[i];
            if (j >= nId) res = Get(*(j = nId));
            else for (res = Get(*j); j < nId; ++j)
                if (res < (tmp = Get(*(j + 1)))) res = tmp;
                else break;
            f[i] = res;
            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

sequence.cpp: In function 'void Cin(int&)':
sequence.cpp:42:19: warning: ISO C++1z does not allow 'register' storage class specifier [-Wregister]
     register char c;
                   ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB contestant found the optimal answer: 108 == 108
2 Correct 2 ms 504 KB contestant found the optimal answer: 999 == 999
3 Correct 2 ms 504 KB contestant found the optimal answer: 0 == 0
4 Correct 2 ms 604 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 2 ms 604 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 2 ms 604 KB contestant found the optimal answer: 1 == 1
7 Correct 2 ms 604 KB contestant found the optimal answer: 1 == 1
8 Correct 2 ms 620 KB contestant found the optimal answer: 1 == 1
9 Correct 2 ms 640 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 2 ms 644 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 2 ms 648 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 2 ms 652 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 2 ms 656 KB contestant found the optimal answer: 140072 == 140072
14 Correct 2 ms 660 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 3 ms 664 KB contestant found the optimal answer: 805 == 805
16 Correct 2 ms 668 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 2 ms 672 KB contestant found the optimal answer: 999919994 == 999919994
# Verdict Execution time Memory Grader output
1 Correct 2 ms 676 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 2 ms 680 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 2 ms 684 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 2 ms 688 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 2 ms 692 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 2 ms 696 KB contestant found the optimal answer: 933702 == 933702
7 Correct 2 ms 712 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 2 ms 716 KB contestant found the optimal answer: 687136 == 687136
9 Correct 2 ms 720 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 2 ms 724 KB contestant found the optimal answer: 29000419931 == 29000419931
# Verdict Execution time Memory Grader output
1 Correct 2 ms 856 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 2 ms 860 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 2 ms 864 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 2 ms 868 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 3 ms 884 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Correct 3 ms 888 KB contestant found the optimal answer: 107630884 == 107630884
7 Correct 3 ms 936 KB contestant found the optimal answer: 475357671774 == 475357671774
8 Correct 2 ms 936 KB contestant found the optimal answer: 193556962 == 193556962
9 Correct 2 ms 936 KB contestant found the optimal answer: 482389919803 == 482389919803
10 Correct 2 ms 936 KB contestant found the optimal answer: 490686959791 == 490686959791
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1540 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 3 ms 1544 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 5 ms 1548 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 3 ms 1556 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 6 ms 1564 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 5 ms 1568 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 7 ms 1572 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 5 ms 1580 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 3 ms 1584 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 4 ms 1588 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# Verdict Execution time Memory Grader output
1 Correct 7 ms 9016 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 10 ms 9064 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Correct 78 ms 9064 KB contestant found the optimal answer: 4973126687469639 == 4973126687469639
4 Correct 11 ms 9104 KB contestant found the optimal answer: 3748491676694116 == 3748491676694116
5 Correct 52 ms 9188 KB contestant found the optimal answer: 1085432199 == 1085432199
6 Correct 58 ms 9188 KB contestant found the optimal answer: 514790755404 == 514790755404
7 Correct 53 ms 9196 KB contestant found the optimal answer: 1256105310476641 == 1256105310476641
8 Correct 53 ms 9372 KB contestant found the optimal answer: 3099592898816 == 3099592898816
9 Correct 57 ms 9372 KB contestant found the optimal answer: 1241131419367412 == 1241131419367412
10 Correct 67 ms 9372 KB contestant found the optimal answer: 1243084101967798 == 1243084101967798
# Verdict Execution time Memory Grader output
1 Correct 107 ms 82932 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Correct 105 ms 83140 KB contestant found the optimal answer: 19874432173 == 19874432173
3 Execution timed out 2054 ms 83660 KB Time limit exceeded
4 Halted 0 ms 0 KB -