From 48cf36e07d1edd0c1fb4e70ac3619b1ca1866758 Mon Sep 17 00:00:00 2001 From: Dmitrii Ushakov Date: Sat, 17 Oct 2026 11:55:50 +0300 Subject: [PATCH] Move from string (not strings) to math + small stylistic fixes --- .../medium/{string => math}/max_problems.toml | 49 ++++--------------- 1 file changed, 9 insertions(+), 40 deletions(-) rename tasks/medium/{string => math}/max_problems.toml (63%) diff --git a/tasks/medium/string/max_problems.toml b/tasks/medium/math/max_problems.toml similarity index 63% rename from tasks/medium/string/max_problems.toml rename to tasks/medium/math/max_problems.toml index b531620..1f05e5d 100644 --- a/tasks/medium/string/max_problems.toml +++ b/tasks/medium/math/max_problems.toml @@ -2,34 +2,32 @@ base_score = 150 # ------------------- Problem metadata ------------------- level = "medium" name = "max_problems" -tags = ["string", "math", "greedy"] +tags = ["math", "greedy", "strings"] time_to_solve_sec = 300 # ------------------- Statements ------------------- description_ru = """ -Во время раунда участнику каждую секунду записывали ЭЭГ в виде строки. Символ «A» означает, что в эту секунду он думал о задаче, любой другой символ — о чём‑то другом. Известно, что над каждой задачей участник размышлял различное количество секунд. Определите максимальное количество задач в раунде. -В примере aAAaAbcdAAtrataAtoAApA участник думал над задачами 9 секунд (количество букв A), это могло быть три задачи со временем размышления 1, 3 и 5 секунд (возможны и другие распределения времени на конкретные задачи). +Во время раунда участнику каждую минуту записывали ЭЭГ в виде строки. Символ «A» означает, что в эту минуту он думал о задаче, любой другой символ — о чём‑то другом. Известно, что над каждой задачей участник размышлял различное количество минут. Определите максимально возможное количество задач в раунде. +В примере aAAaAbcdAAtrataAtoAApA участник думал над задачами 9 минут (количество букв A), это могло быть три задачи со временем размышления 1, 3 и 5 минут (возможны и другие распределения времени на конкретные задачи). """ description_en = """ -During the round, the participant’s EEG was recorded every second as a string. The character ‘A’ indicates that at that second he was thinking about a problem, while any other character means he was thinking about something else. It is known that the participant thought about each problem for a different number of seconds. Determine the maximum possible number of problems in the round. -In the example of aAAaAbcdAAtrataAtoAApA, the participant thought about the tasks for 9 seconds (the number of letters A), it could be three tasks with a reflection time of 1, 3 and 5 seconds (other time distributions for specific tasks are possible). +During the round, the participant’s EEG was recorded every minute as a string. The character ‘A’ indicates that at that minute he was thinking about a problem, while any other character means he was thinking about something else. It is known that the participant thought about each problem for a different number of minutes. Determine the maximum possible number of problems in the round. +In the example of aAAaAbcdAAtrataAtoAApA, the participant thought about the tasks for 9 minutes (the number of letters A), it could be three tasks with a reflection time of 1, 3 and 5 minutes (other time distributions for specific tasks are possible). """ # ------------------- Reference solution ------------------- solution = """ def solution(eeg: str) -> int: - \"\"\"Return the maximal number of distinct‑length problem‑thinking intervals. - + \"\"\" The only thing that matters is the total count of the character 'A'. We need the largest k such that 1 + 2 + … + k ≤ N, where N = number of 'A's. The answer is floor((sqrt(1 + 8·N) - 1) / 2). \"\"\" - import math + from math import isqrt - n = eeg.count('A') # total seconds spent thinking about problems - # integer square root gives floor(sqrt(...)) - return (math.isqrt(1 + 8 * n) - 1) // 2 + n = eeg.count('A') + return (isqrt(1 + 8 * n) - 1) // 2 """ examples = """ @@ -50,147 +48,118 @@ name = "integer" arguments = [""] expected = 0 - [[asserts]] arguments = ["b"] expected = 0 - [[asserts]] arguments = ["A"] expected = 1 - [[asserts]] arguments = ["AA"] expected = 1 - [[asserts]] arguments = ["AAA"] expected = 2 - [[asserts]] arguments = ["AAAA"] expected = 2 - [[asserts]] arguments = ["AAAAA"] expected = 2 - [[asserts]] arguments = ["AAAAAA"] expected = 3 - [[asserts]] arguments = ["AAAAAAA"] expected = 3 - [[asserts]] arguments = ["AAAAAAAA"] expected = 3 - [[asserts]] arguments = ["AAAAAAAAA"] expected = 3 - [[asserts]] arguments = ["AAAAAAAAAA"] expected = 4 - [[asserts]] arguments = ["AAAAAAAAAAA"] expected = 4 - [[asserts]] arguments = ["AAAAAAAAAAAA"] expected = 4 - [[asserts]] arguments = ["AAAAAAAAAAAAAAA"] expected = 5 - [[asserts]] arguments = ["aAa"] expected = 1 - [[asserts]] arguments = ["aAAaAbcdAAtrataAtoAApA"] expected = 3 - [[asserts]] arguments = ["rockArollAA"] expected = 2 - [[asserts]] arguments = ["BBBBBAAAAAAB"] expected = 3 - [[asserts]] arguments = ["AaAaAaAa"] expected = 2 - [[asserts]] arguments = ["AAAxxxAAA"] expected = 3 - [[asserts]] arguments = ["xAxAxAxAxA"] expected = 2 - [[asserts]] arguments = ["AAAAAAAAAAAAAAAAAAAAA"] expected = 6 - [[asserts]] arguments = ["AAAAAAAAAAAAAAAAAAAAAAAAAAAA"] expected = 7 - [[asserts]] arguments = ["no_uppercase_a"] expected = 0 - [[asserts]] arguments = ["aA"] expected = 1 - [[asserts]] arguments = ["AAaAAaAA"] expected = 3 - [[asserts]] arguments = ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"] expected = 8 - [[asserts]] arguments = ["AxxAxxAxxAxxAxxAxxAxxAxxA"] expected = 3 - [[asserts]] arguments = ["AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA"] expected = 9