fix: changed problem time_limit back to 1s, and updated python solution.
This commit is contained in:
Binary file not shown.
Binary file not shown.
@@ -1,7 +1,7 @@
|
||||
\documentclass{maratona}
|
||||
|
||||
\begin{document}
|
||||
\begin{ProblemaAutor}{}{Estouro}{1.5}{256}{Arthur Andrade D'Olival}
|
||||
\begin{ProblemaAutor}{}{Estouro}{1}{256}{Arthur Andrade D'Olival}
|
||||
|
||||
No laboratório de experimentos caóticos da \textbf{Fábrica de Balões Numéricos}, um cientista excêntrico te entrega uma fileira de balões, cada um pintado com um número inteiro positivo.
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
"problem": {
|
||||
"title": "Estouro",
|
||||
"event": "",
|
||||
"time_limit": 1.5,
|
||||
"time_limit": 1.0,
|
||||
"memory_limit_mb": 256,
|
||||
"input_file": "stdin",
|
||||
"output_file": "stdout",
|
||||
|
||||
@@ -1,31 +1,14 @@
|
||||
n = int(input())
|
||||
arr = list(map(int, input().split()))
|
||||
nums = list(map(int, input().split()))
|
||||
|
||||
nums = [1] + arr + [1]
|
||||
m = n + 2
|
||||
nums = [1] + nums + [1]
|
||||
|
||||
dp = [[0] * m for _ in range(m)]
|
||||
dp = [[0] * len(nums) for _ in range(len(nums))]
|
||||
|
||||
for length in range(2, m):
|
||||
for left in range(m - length):
|
||||
right = left + length
|
||||
for length in range(3, len(nums) + 1):
|
||||
for i in range(len(nums) - length + 1):
|
||||
j = i + length - 1
|
||||
for k in range(i + 1, j):
|
||||
dp[i][j] = max(dp[i][j], dp[i][k] + dp[k][j] + nums[i] * nums[k] * nums[j])
|
||||
|
||||
best = 0
|
||||
left_val = nums[left]
|
||||
right_val = nums[right]
|
||||
|
||||
row_left = dp[left]
|
||||
|
||||
for k in range(left + 1, right):
|
||||
val = (
|
||||
row_left[k]
|
||||
+ dp[k][right]
|
||||
+ left_val * nums[k] * right_val
|
||||
)
|
||||
|
||||
if val > best:
|
||||
best = val
|
||||
|
||||
row_left[right] = best
|
||||
|
||||
print(dp[0][m - 1])
|
||||
print(dp[0][len(nums) - 1])
|
||||
Reference in New Issue
Block a user