Submission #3222844


Source Code Expand

Copy
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(10000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(N, X, x):

    x.reverse()
    sa = [0]
    for a in x:
        sa.append(sa[-1]+a)

    ans = sys.maxsize
    for k in range(1, N+1):
        t = X*N
        for j in range(1, math.ceil(N/k)+1):
            s = (j-1)*k
            e = (j)*k
            if e >= len(sa):
                e = len(sa)-1

            if j == 1:
                t += 5*(sa[e]-sa[s])
            else:
                t += (2*j+1)*(sa[e]-sa[s])

        t += k*X
        ans = min(ans, t)
    return ans


def main():
    N, X = read_int_n()
    x = read_int_n()
    print(slv(N, X, x))


if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task B - Garbage Collector
User patahene
Language PyPy3 (2.4.0)
Score 700
Code Size 1702 Byte
Status
Exec Time 466 ms
Memory 119376 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt
Subtask1 400 / 400 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, stest_01.txt, stest_02.txt, stest_03.txt, stest_04.txt, stest_05.txt, stest_06.txt, stest_07.txt, stest_08.txt, stest_09.txt, stest_10.txt, stest_11.txt, stest_12.txt
All 300 / 300 sample_01.txt, sample_02.txt, sample_03.txt, sample_04.txt, stest_01.txt, stest_02.txt, stest_03.txt, stest_04.txt, stest_05.txt, stest_06.txt, stest_07.txt, stest_08.txt, stest_09.txt, stest_10.txt, stest_11.txt, stest_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt
Case Name Status Exec Time Memory
sample_01.txt 332 ms 64364 KB
sample_02.txt 258 ms 59628 KB
sample_03.txt 261 ms 59628 KB
sample_04.txt 255 ms 59628 KB
stest_01.txt 286 ms 62060 KB
stest_02.txt 284 ms 61804 KB
stest_03.txt 258 ms 59628 KB
stest_04.txt 259 ms 59628 KB
stest_05.txt 281 ms 61676 KB
stest_06.txt 281 ms 60780 KB
stest_07.txt 273 ms 60908 KB
stest_08.txt 285 ms 61804 KB
stest_09.txt 277 ms 60908 KB
stest_10.txt 284 ms 60908 KB
stest_11.txt 287 ms 61804 KB
stest_12.txt 269 ms 60140 KB
test_13.txt 466 ms 119376 KB
test_14.txt 466 ms 119376 KB
test_15.txt 309 ms 66924 KB
test_16.txt 420 ms 106828 KB
test_17.txt 426 ms 106828 KB
test_18.txt 294 ms 64960 KB
test_19.txt 440 ms 110728 KB
test_20.txt 444 ms 110600 KB
test_21.txt 429 ms 110600 KB
test_22.txt 440 ms 110600 KB
test_23.txt 423 ms 106828 KB
test_24.txt 425 ms 106828 KB
test_25.txt 349 ms 78800 KB
test_26.txt 431 ms 110600 KB
test_27.txt 436 ms 110600 KB
test_28.txt 399 ms 101480 KB