# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
197945 | 2020-01-24T11:47:51 Z | songc | 수열 (APIO14_sequence) | C++14 | 344 ms | 131076 KB |
#include <bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL,LL> pii; int N, K; LL S[101010]; int P[101010][220]; struct Line{ LL m, k; int id; }; bool popchk(Line a, Line b, Line c){ return ((__int128)b.k-c.k)*(b.m-a.m) <= ((__int128)a.k-b.k)*(c.m-b.m); } struct ConvHull{ vector<Line> V; int p; void push(Line l){ if (!V.empty() && V.back().m == l.m) return; while (V.size()>2 && popchk(V[V.size()-2], V.back(), l)){ V.pop_back(); if (V.size() <= p) p--; } V.push_back(l); } pii read(LL x){ while (p < V.size()-1 && V[p].m*x+V[p].k <= V[p+1].m*x+V[p+1].k) p++; return pii(V[p].m*x+V[p].k, V[p].id); } } CHT[220]; int main(){ scanf("%d %d", &N, &K); K++; for (int i=1; i<=N; i++){ scanf("%lld", &S[i]); S[i] += S[i-1]; } CHT[0].push((Line){0, 0, 0}); for (int i=1; i<=N; i++){ for (int j=1; j<=min(i, K); j++){ LL ret; tie(ret, P[i][j]) = CHT[j-1].read(S[i]); if (i == N && j == K) printf("%lld\n", ret); CHT[j].push((Line){S[i], ret-S[i]*S[i], i}); } } for (int i=K-1, p=P[N][K]; i; p=P[p][i], i--) printf("%d ", p); printf("\n"); return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 376 KB | contestant found the optimal answer: 108 == 108 |
2 | Correct | 2 ms | 376 KB | contestant found the optimal answer: 999 == 999 |
3 | Incorrect | 2 ms | 376 KB | Integer 2 violates the range [1, 1] |
4 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 380 KB | contestant found the optimal answer: 1093956 == 1093956 |
2 | Correct | 2 ms | 376 KB | contestant found the optimal answer: 302460000 == 302460000 |
3 | Correct | 2 ms | 504 KB | contestant found the optimal answer: 122453454361 == 122453454361 |
4 | Correct | 2 ms | 376 KB | contestant found the optimal answer: 93663683509 == 93663683509 |
5 | Correct | 3 ms | 376 KB | contestant found the optimal answer: 1005304678 == 1005304678 |
6 | Correct | 1 ms | 376 KB | contestant found the optimal answer: 933702 == 933702 |
7 | Correct | 2 ms | 376 KB | contestant found the optimal answer: 25082842857 == 25082842857 |
8 | Correct | 2 ms | 376 KB | contestant found the optimal answer: 687136 == 687136 |
9 | Correct | 3 ms | 376 KB | contestant found the optimal answer: 27295930079 == 27295930079 |
10 | Correct | 2 ms | 376 KB | contestant found the optimal answer: 29000419931 == 29000419931 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 2 ms | 504 KB | contestant found the optimal answer: 610590000 == 610590000 |
2 | Correct | 2 ms | 504 KB | contestant found the optimal answer: 311760000 == 311760000 |
3 | Correct | 4 ms | 1272 KB | contestant found the optimal answer: 1989216017013 == 1989216017013 |
4 | Correct | 2 ms | 504 KB | contestant found the optimal answer: 1499437552673 == 1499437552673 |
5 | Correct | 3 ms | 1016 KB | contestant found the optimal answer: 1019625819 == 1019625819 |
6 | Incorrect | 4 ms | 1016 KB | Integer 200 violates the range [1, 199] |
7 | Halted | 0 ms | 0 KB | - |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 1272 KB | contestant found the optimal answer: 21503404 == 21503404 |
2 | Correct | 3 ms | 1400 KB | contestant found the optimal answer: 140412195 == 140412195 |
3 | Correct | 12 ms | 6136 KB | contestant found the optimal answer: 49729674225461 == 49729674225461 |
4 | Correct | 3 ms | 1400 KB | contestant found the optimal answer: 37485571387523 == 37485571387523 |
5 | Correct | 12 ms | 5880 KB | contestant found the optimal answer: 679388326 == 679388326 |
6 | Correct | 11 ms | 5112 KB | contestant found the optimal answer: 4699030287 == 4699030287 |
7 | Correct | 13 ms | 6264 KB | contestant found the optimal answer: 12418819758185 == 12418819758185 |
8 | Correct | 13 ms | 6136 KB | contestant found the optimal answer: 31093317350 == 31093317350 |
9 | Correct | 5 ms | 2296 KB | contestant found the optimal answer: 12194625429236 == 12194625429236 |
10 | Correct | 7 ms | 3192 KB | contestant found the optimal answer: 12345131038664 == 12345131038664 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 9940 KB | contestant found the optimal answer: 1818678304 == 1818678304 |
2 | Correct | 11 ms | 10044 KB | contestant found the optimal answer: 1326260195 == 1326260195 |
3 | Correct | 137 ms | 64336 KB | contestant found the optimal answer: 4973126687469639 == 4973126687469639 |
4 | Correct | 9 ms | 10108 KB | contestant found the optimal answer: 3748491676694116 == 3748491676694116 |
5 | Correct | 68 ms | 32760 KB | contestant found the optimal answer: 1085432199 == 1085432199 |
6 | Correct | 73 ms | 32768 KB | contestant found the optimal answer: 514790755404 == 514790755404 |
7 | Correct | 116 ms | 50460 KB | contestant found the optimal answer: 1256105310476641 == 1256105310476641 |
8 | Correct | 96 ms | 42852 KB | contestant found the optimal answer: 3099592898816 == 3099592898816 |
9 | Correct | 100 ms | 46080 KB | contestant found the optimal answer: 1241131419367412 == 1241131419367412 |
10 | Correct | 123 ms | 55288 KB | contestant found the optimal answer: 1243084101967798 == 1243084101967798 |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 103 ms | 94928 KB | contestant found the optimal answer: 19795776960 == 19795776960 |
2 | Correct | 103 ms | 94804 KB | contestant found the optimal answer: 19874432173 == 19874432173 |
3 | Runtime error | 344 ms | 131076 KB | Execution killed with signal 9 (could be triggered by violating memory limits) |
4 | Halted | 0 ms | 0 KB | - |