Submission #1605182


Source Code Expand

from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    N = int(input())
    a = list(map(int, input().split()))

    idx = {}
    for i in range(N):
        idx[a[i]] = i

    left_idx, right_idx = list(range(N + 1)), list(range(N + 1))
    ans = 0
    for a in range(N, 0, -1):
        i = idx[a]
        l, r = left_idx[i], right_idx[i]
        ans += (i - l + 1) * (r - i + 1) * a

        left_idx[r + 1] = l
        right_idx[l - 1] = r

    print(ans)


if __name__ == '__main__':
    main()

Submission Info

Submission Time
Task B - Minimum Sum
User MitI_7
Language Python (3.4.3)
Score 400
Code Size 739 Byte
Status AC
Exec Time 288 ms
Memory 47260 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 13
Set Name Test Cases
Sample example0, example1, example2
All corner0, corner1, corner2, corner3, example0, example1, example2, maxrand0, maxrand1, maxrand2, rand0, rand1, rand2
Case Name Status Exec Time Memory
corner0 AC 189 ms 45624 KB
corner1 AC 184 ms 47260 KB
corner2 AC 21 ms 3316 KB
corner3 AC 197 ms 45624 KB
example0 AC 21 ms 3316 KB
example1 AC 20 ms 3316 KB
example2 AC 21 ms 3316 KB
maxrand0 AC 274 ms 45752 KB
maxrand1 AC 288 ms 45748 KB
maxrand2 AC 281 ms 45624 KB
rand0 AC 21 ms 3316 KB
rand1 AC 21 ms 3316 KB
rand2 AC 21 ms 3316 KB