Submission #670199

# Submission time Handle Problem Language Result Execution time Memory
670199 2022-12-08T09:22:05 Z yyhjin12 Split the sequence (APIO14_sequence) PyPy 3
71 / 100
436 ms 131072 KB
import sys
from collections import deque
input = sys.stdin.readline
    
def intersect(L1, L2):
    return (L2[1]-L1[1])/(L1[0]-L2[0])

N, K = map(int, input().split())
psum = list(map(int, input().split()))

#Prefix Sum
for i in range(1, N): psum[i] += psum[i-1]

#Initialize DP Table
prev = [[0]*N for _ in range(K)]
DP = [[0]*N for _ in range(2)]

for k in range(K):
    F = deque(); F.append((0, int(-1e14), -1, -1))
    for i in range(k+1, N):
        g = (psum[i-1], DP[(k%2)^1][i-1]-psum[i-1]*psum[i-1], 0, i-1)
        if F[-1][0] == g[0] and F[-1][1] < g[1]:
            F.pop()
            while F:
                g = (g[0], g[1], intersect(F[-1], g), g[3])
                if F[-1][2] < g[2]: break
                F.pop()
            F.append(g)

        elif F[-1][0] != g[0]:
            while F:
                g = (g[0], g[1], intersect(F[-1], g), g[3])
                if F[-1][2] < g[2]: break
                F.pop()
            F.append(g)

        X = psum[i]
        while len(F)>1 and F[1][2] < X: F.popleft()
        DP[k%2][i] = F[0][0] * X + F[0][1]
        prev[k][i] = F[0][3]

print(DP[(K-1)%2][N-1])

temp = N-1; q = K-1; L = []
while q>=0:
    L.append(prev[q][temp]+1)
    temp = prev[q][temp]; q -= 1
L.sort()
print(' '.join(map(str, L)))
# Verdict Execution time Memory Grader output
1 Correct 42 ms 18692 KB contestant found the optimal answer: 108 == 108
2 Correct 42 ms 18636 KB contestant found the optimal answer: 999 == 999
3 Correct 40 ms 18608 KB contestant found the optimal answer: 0 == 0
4 Correct 40 ms 18556 KB contestant found the optimal answer: 1542524 == 1542524
5 Correct 43 ms 18588 KB contestant found the optimal answer: 4500000000 == 4500000000
6 Correct 41 ms 18604 KB contestant found the optimal answer: 1 == 1
7 Correct 40 ms 18556 KB contestant found the optimal answer: 1 == 1
8 Correct 40 ms 18592 KB contestant found the optimal answer: 1 == 1
9 Correct 48 ms 18516 KB contestant found the optimal answer: 100400096 == 100400096
10 Correct 44 ms 18604 KB contestant found the optimal answer: 900320000 == 900320000
11 Correct 40 ms 18640 KB contestant found the optimal answer: 3698080248 == 3698080248
12 Correct 42 ms 18632 KB contestant found the optimal answer: 3200320000 == 3200320000
13 Correct 40 ms 18656 KB contestant found the optimal answer: 140072 == 140072
14 Correct 45 ms 18592 KB contestant found the optimal answer: 376041456 == 376041456
15 Correct 40 ms 18560 KB contestant found the optimal answer: 805 == 805
16 Correct 45 ms 18604 KB contestant found the optimal answer: 900189994 == 900189994
17 Correct 40 ms 18528 KB contestant found the optimal answer: 999919994 == 999919994
# Verdict Execution time Memory Grader output
1 Correct 44 ms 18704 KB contestant found the optimal answer: 1093956 == 1093956
2 Correct 41 ms 18696 KB contestant found the optimal answer: 302460000 == 302460000
3 Correct 61 ms 20224 KB contestant found the optimal answer: 122453454361 == 122453454361
4 Correct 44 ms 18656 KB contestant found the optimal answer: 93663683509 == 93663683509
5 Correct 43 ms 18696 KB contestant found the optimal answer: 1005304678 == 1005304678
6 Correct 43 ms 18660 KB contestant found the optimal answer: 933702 == 933702
7 Correct 47 ms 18680 KB contestant found the optimal answer: 25082842857 == 25082842857
8 Correct 47 ms 18740 KB contestant found the optimal answer: 687136 == 687136
9 Correct 43 ms 18636 KB contestant found the optimal answer: 27295930079 == 27295930079
10 Correct 44 ms 18668 KB contestant found the optimal answer: 29000419931 == 29000419931
# Verdict Execution time Memory Grader output
1 Correct 46 ms 18804 KB contestant found the optimal answer: 610590000 == 610590000
2 Correct 47 ms 18704 KB contestant found the optimal answer: 311760000 == 311760000
3 Correct 89 ms 22284 KB contestant found the optimal answer: 1989216017013 == 1989216017013
4 Correct 47 ms 18664 KB contestant found the optimal answer: 1499437552673 == 1499437552673
5 Correct 102 ms 23824 KB contestant found the optimal answer: 1019625819 == 1019625819
6 Correct 109 ms 24488 KB contestant found the optimal answer: 107630884 == 107630884
7 Correct 102 ms 23460 KB contestant found the optimal answer: 475357671774 == 475357671774
8 Correct 66 ms 20704 KB contestant found the optimal answer: 193556962 == 193556962
9 Correct 78 ms 21544 KB contestant found the optimal answer: 482389919803 == 482389919803
10 Correct 88 ms 22704 KB contestant found the optimal answer: 490686959791 == 490686959791
# Verdict Execution time Memory Grader output
1 Correct 70 ms 20704 KB contestant found the optimal answer: 21503404 == 21503404
2 Correct 63 ms 20684 KB contestant found the optimal answer: 140412195 == 140412195
3 Correct 122 ms 25640 KB contestant found the optimal answer: 49729674225461 == 49729674225461
4 Correct 64 ms 20960 KB contestant found the optimal answer: 37485571387523 == 37485571387523
5 Correct 124 ms 25400 KB contestant found the optimal answer: 679388326 == 679388326
6 Correct 134 ms 25648 KB contestant found the optimal answer: 4699030287 == 4699030287
7 Correct 135 ms 25776 KB contestant found the optimal answer: 12418819758185 == 12418819758185
8 Correct 141 ms 25768 KB contestant found the optimal answer: 31093317350 == 31093317350
9 Correct 95 ms 23076 KB contestant found the optimal answer: 12194625429236 == 12194625429236
10 Correct 116 ms 24532 KB contestant found the optimal answer: 12345131038664 == 12345131038664
# Verdict Execution time Memory Grader output
1 Correct 129 ms 26744 KB contestant found the optimal answer: 1818678304 == 1818678304
2 Correct 125 ms 26712 KB contestant found the optimal answer: 1326260195 == 1326260195
3 Correct 423 ms 52672 KB contestant found the optimal answer: 4973126687469639 == 4973126687469639
4 Correct 102 ms 26736 KB contestant found the optimal answer: 3748491676694116 == 3748491676694116
5 Correct 369 ms 43084 KB contestant found the optimal answer: 1085432199 == 1085432199
6 Correct 370 ms 41644 KB contestant found the optimal answer: 514790755404 == 514790755404
7 Correct 436 ms 46864 KB contestant found the optimal answer: 1256105310476641 == 1256105310476641
8 Correct 367 ms 43520 KB contestant found the optimal answer: 3099592898816 == 3099592898816
9 Correct 372 ms 45524 KB contestant found the optimal answer: 1241131419367412 == 1241131419367412
10 Correct 424 ms 50732 KB contestant found the optimal answer: 1243084101967798 == 1243084101967798
# Verdict Execution time Memory Grader output
1 Correct 272 ms 48792 KB contestant found the optimal answer: 19795776960 == 19795776960
2 Correct 299 ms 53208 KB contestant found the optimal answer: 19874432173 == 19874432173
3 Runtime error 118 ms 131072 KB Execution killed with signal 9
4 Halted 0 ms 0 KB -