Official

A - Divide String Editorial by evima


In this problem, the following turns out to be true:

  • there is a division of \(S\) that satisfies the conditions \(\Leftrightarrow\) “there is a length-\(2\) division of \(S\) that satisfies the conditions.

    \(\Leftarrow\) is obvious. Let’s prove \(\Rightarrow\).

    Suppose that the division \(S= t_1 + t_2 + ... + t_k(k \ge 3)\) is valid. Then, the length-\(2\) division \((t_1,t_2+t_3+\dots + t_k)\) is also valid. This is because \(t_1 < t_2\) and \(t_2 < t_2 + t_3 + \dots + t_k\) in lexicographical order, from which we have \(t_1 < t_2 + t_3 + \dots + t_k\).

    Therefore, all you need to do is to check whether there is a length-\(2\) division of \(S\) that is strictly increasing in lexicographical order. There are \(N-1\) length-\(2\) divisions, and by spending \(\mathrm{O}(N)\) time on each judgment, you can solve this problem in \(\mathrm{O}(N^2)\) time.

    (Modified the first draft written by GPT-4.)

  • posted:
    last update: