diff --git a/estouro/estouro-tutorial.pdf b/estouro/estouro-tutorial.pdf index aa18c53..442d5a8 100644 Binary files a/estouro/estouro-tutorial.pdf and b/estouro/estouro-tutorial.pdf differ diff --git a/estouro/estouro.pdf b/estouro/estouro.pdf index d760b8a..9a9615f 100644 Binary files a/estouro/estouro.pdf and b/estouro/estouro.pdf differ diff --git a/estouro/estouro.tex b/estouro/estouro.tex index 11edfb0..e8352d2 100644 --- a/estouro/estouro.tex +++ b/estouro/estouro.tex @@ -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. diff --git a/estouro/problem.json b/estouro/problem.json index 252fd30..996a41b 100644 --- a/estouro/problem.json +++ b/estouro/problem.json @@ -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", diff --git a/estouro/src/alternative-ac.py b/estouro/src/alternative-ac.py index e94c881..a44cc96 100644 --- a/estouro/src/alternative-ac.py +++ b/estouro/src/alternative-ac.py @@ -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]) \ No newline at end of file +print(dp[0][len(nums) - 1]) \ No newline at end of file