Submission #3222843


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 Python3 (3.4.3)
Score 700
Code Size 1702 Byte
Status
Exec Time 1534 ms
Memory 28132 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 61 ms 6632 KB
sample_02.txt 40 ms 5484 KB
sample_03.txt 37 ms 5484 KB
sample_04.txt 37 ms 5484 KB
stest_01.txt 48 ms 5612 KB
stest_02.txt 47 ms 5612 KB
stest_03.txt 38 ms 5484 KB
stest_04.txt 38 ms 5356 KB
stest_05.txt 45 ms 5484 KB
stest_06.txt 43 ms 5484 KB
stest_07.txt 47 ms 5484 KB
stest_08.txt 47 ms 5484 KB
stest_09.txt 41 ms 5484 KB
stest_10.txt 47 ms 5612 KB
stest_11.txt 48 ms 5612 KB
stest_12.txt 39 ms 5484 KB
test_13.txt 1508 ms 27548 KB
test_14.txt 1534 ms 27512 KB
test_15.txt 309 ms 9956 KB
test_16.txt 1480 ms 27148 KB
test_17.txt 1454 ms 27460 KB
test_18.txt 217 ms 8684 KB
test_19.txt 1511 ms 26536 KB
test_20.txt 1519 ms 28120 KB
test_21.txt 1496 ms 26536 KB
test_22.txt 1475 ms 28132 KB
test_23.txt 1487 ms 27276 KB
test_24.txt 1474 ms 27460 KB
test_25.txt 746 ms 16572 KB
test_26.txt 1505 ms 26536 KB
test_27.txt 1471 ms 27952 KB
test_28.txt 1218 ms 22396 KB