def word_break(text, dictionary):
    words = {word for word in dictionary if word}
    limit = min(len(text), max(map(len, words), default=0))
    dp = [False] * (len(text) + 1)
    dp[0] = True
    for end in range(1, len(text) + 1):
        for start in range(max(0, end - limit), end):
            if dp[start] and text[start:end] in words:
                dp[end] = True
                break
    return dp[-1]
