Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 = """
Expand All @@ -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
Loading