問題一覧 > 通常問題

No.1512 Composition

レベル : / AI推定難易度 : 1200 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 197
作問者 : ぷら / テスター : nok0 だれ
お気に入りにしたユーザー ProblemId : 6480 / 自分の提出
問題文最終更新日: 2021-05-21 23:43:55
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 296 (順位表) の他の問題:

Problem Statement

For a string $t$, if the characters of $t$ are arranged in ascending order, we call $t$ a good string.

For example, aabc,axz, the empty string, and so on are good strings, but cba,aza, and so on are not good strings.

You are given $N$ strings consisting of lowercase English letters.

For each of the $N$ strings, choose whether to select it or not, and concatenate the selected strings in any order to form a good string $X$. Find the maximum possible length of $X$.

Input

$N$
$S_1$
$S_2$
$\vdots$
$S_N$

  • $N$ is an integer.
  • $S_i\ (1 \leq i \leq N)$ is a string consisting only of lowercase English letters.
  • $1 \leq N \leq 200000$
  • $1 \leq |S_i| \leq 200000$
  • The sum of $|S_i|$ given in a single input does not exceed $200000$.
  • Output

    Output the answer, followed by a newline.

    Sample

    Sample 1
    Input
    3
    aa
    ab
    ba
    
    Output
    4

    The maximum is achieved by $S_1+S_2=$aaab.

    Sample 2
    Input
    3
    cba
    db
    kji
    
    Output
    0

    It may be impossible to form a good string of length $1$ or more.

    Sample 3
    Input
    4
    abc
    ab
    bbccdd
    de
    
    Output
    10

    Strings such as abcde, abbbccddde are possible; among these, output the maximum length, $10$.

    Sample 4
    Input
    3
    ab
    cd
    f
    
    Output
    5

    提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。