Submission #88024

# Submission time Handle Problem Language Result Execution time Memory
88024 2018-12-03T13:06:40 Z vanbang9710 Split the sequence (APIO14_sequence) C++14
71 / 100
129 ms 132096 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;

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 = 201;

int trace[maxN][maxK], s[maxN], nId, N, K, a;
static ll f[maxN][maxK];

struct TLine
{
    int x;
    ll y;
    inline TLine operator - (const TLine &l) const & { return {x - l.x, y - l.y}; }
    inline bool operator * (const TLine &l) const & { return x * l.y <= y * l.x; }
} p[maxN];
int id[maxN];
inline bool Erase(int a, int b, int c)
{
    return (p[b] - p[a]) * (p[a] - p[c]);
}

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 = 1; k <= K; ++k)
    {
        nId = -1;
        int j = 0;
        for (int i = k, val = f[i][k - 1]; i < N; ++i)
        {
            --i;
            p[i] = {s[i], f[i][k - 1] - (ll)s[i] * s[i]};
            while (nId >= 1 && Erase(id[nId - 1], id[nId], i)) --nId;
            id[++nId] = i;
            val = f[++i][k - 1];
            int t = s[i];
            #define Get(i) ((ll)t * p[i].x + p[i].y)
            if (j >= nId) j = nId;
            else while (j < nId && Get(id[j + 1]) > Get(id[j])) ++j;
            f[i][k] = Get(id[j]);
            trace[i][k] = id[j];
        }
    }
    cout << f[N - 1][K] << '\n';
    int i = N - 1;
    for (; K > 0; --K)
        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

sequence.cpp: In function 'int main()':
sequence.cpp:83:25: warning: variable 'val' set but not used [-Wunused-but-set-variable]
         for (int i = k, val = f[i][k - 1]; i < N; ++i)
                         ^~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB contestant found the optimal answer: 108 == 108
2 Correct 2 ms 500 KB contestant found the optimal answer: 999 == 999
3 Correct 2 ms 500 KB contestant found the optimal answer: 0 == 0
4 Correct 2 ms 500 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 2 ms 500 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 3 ms 544 KB contestant found the optimal answer: 1 == 1
7 Correct 2 ms 576 KB contestant found the optimal answer: 1 == 1
8 Correct 3 ms 648 KB contestant found the optimal answer: 1 == 1
9 Correct 2 ms 648 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 2 ms 684 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 2 ms 816 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 3 ms 816 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 3 ms 816 KB contestant found the optimal answer: 140072 == 140072
14 Correct 2 ms 816 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 2 ms 816 KB contestant found the optimal answer: 805 == 805
16 Correct 2 ms 816 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 3 ms 816 KB contestant found the optimal answer: 999919994 == 999919994
# Verdict Execution time Memory Grader output
1 Correct 2 ms 816 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 2 ms 816 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 3 ms 816 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 3 ms 816 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 2 ms 816 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 2 ms 816 KB contestant found the optimal answer: 933702 == 933702
7 Correct 3 ms 820 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 3 ms 824 KB contestant found the optimal answer: 687136 == 687136
9 Correct 2 ms 832 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 2 ms 832 KB contestant found the optimal answer: 29000419931 == 29000419931
# Verdict Execution time Memory Grader output
1 Correct 3 ms 1092 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 3 ms 1092 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 3 ms 1220 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 3 ms 1220 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 3 ms 1220 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Correct 3 ms 1224 KB contestant found the optimal answer: 107630884 == 107630884
7 Correct 3 ms 1228 KB contestant found the optimal answer: 475357671774 == 475357671774
8 Correct 3 ms 1232 KB contestant found the optimal answer: 193556962 == 193556962
9 Correct 3 ms 1232 KB contestant found the optimal answer: 482389919803 == 482389919803
10 Correct 3 ms 1232 KB contestant found the optimal answer: 490686959791 == 490686959791
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3032 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 4 ms 3032 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 7 ms 3032 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 3 ms 3032 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 8 ms 3040 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 8 ms 3044 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 8 ms 3068 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 8 ms 3068 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 5 ms 3076 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 6 ms 3076 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# Verdict Execution time Memory Grader output
1 Correct 22 ms 24572 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 21 ms 24572 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Correct 129 ms 24572 KB contestant found the optimal answer: 4973126687469639 == 4973126687469639
4 Correct 23 ms 24572 KB contestant found the optimal answer: 3748491676694116 == 3748491676694116
5 Correct 85 ms 24620 KB contestant found the optimal answer: 1085432199 == 1085432199
6 Correct 100 ms 24644 KB contestant found the optimal answer: 514790755404 == 514790755404
7 Correct 102 ms 24768 KB contestant found the optimal answer: 1256105310476641 == 1256105310476641
8 Correct 85 ms 24768 KB contestant found the optimal answer: 3099592898816 == 3099592898816
9 Correct 95 ms 24768 KB contestant found the optimal answer: 1241131419367412 == 1241131419367412
10 Correct 117 ms 24916 KB contestant found the optimal answer: 1243084101967798 == 1243084101967798
# Verdict Execution time Memory Grader output
1 Runtime error 109 ms 132096 KB Execution killed with signal 9 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -