a708: Polycarp Writes a String from Memory ( Polycarp 從記憶中寫入字符串 )
Tags : 800 greedy strings
Accepted rate : 20人/22人 ( 91% ) [非即時]
評分方式:
Tolerant

最近更新 : 2022-08-03 08:04

Content

Polycarp has a poor memory. Each day he can remember no more than 3 of different letters.

Polycarp wants to write a non-empty string of s consisting of lowercase Latin letters, taking minimum number of days. In how many days will he be able to do it?

Polycarp initially has an empty string and can only add characters to the end of that string.

For example, if Polycarp wants to write the string lollipops, he will do it in 2 days:

  • on the first day Polycarp will memorize the letters l, o, i and write lolli;
  • On the second day Polycarp will remember the letters p, o, s, add pops to the resulting line and get the line lollipops.

If Polycarp wants to write the string stringology, he will do it in 4 days:

  • in the first day will be written part str;
  • on day two will be written part ing;
  • on the third day, part of olog will be written;
  • on the fourth day, part of y will be written.

For a given string s, print the minimum number of days it will take Polycarp to write it.

Polycarp 的記憶力很差。 每天他能記住的不同字母不超過 3 個。

Polycarp 想要寫一個由小寫拉丁字母組成的非空字符串 s,需要最少的天數。 幾天后他能做到?

Polycarp 最初有一個空字符串,並且只能在該字符串的末尾添加字符。

比如Polycarp想寫字符串 lollipops,他會在2天內完成:

第一天,Polycarp 會記住字母 l、o、i 並寫出 lolli;
第二天,Polycarp 將記住字母 p、o、s,將 pops 添加到結果行中並得到 lollipops。

如果 Polycarp 想寫 stringology,他會在 4 天內完成:

第一天將寫 str;
第二天將寫 ing;
第三天將寫 olog;
第四天,y 被寫入。

對於給定的字符串 s,打印 Polycarp 編寫它所需的最少天數。

Input

The first line of input data contains a single integer t (1 ≤ t ≤ 104) — the number of test cases.

Each test case consists of a non-empty string s consisting of lowercase Latin letters (the length of the string s does not exceed 2⋅105) — the string Polycarp wants to construct.

It is guaranteed that the sum of string lengths s over all test cases does not exceed 2⋅105.

輸入數據的第一行包含一個整數 t (1 ≤ t ≤ 104) — 測試用例的數量。

每個測試用例都包含一個由小寫拉丁字母組成的非空字符串 s(字符串 s 的長度不超過 2⋅105)——Polycarp 想要構建的字符串。

保證所有測試用例的字符串長度總和 s 不超過 2⋅105

Output

For each test case, print a single number — minimum number of days it will take Polycarp to write the string s from memory.

對於每個測試用例,打印一個數字 — Polycarp 從內存中寫入字符串 s 所需的最少天數。

Sample Input #1
6
lollipops
stringology
abracadabra
codeforces
test
f
Sample Output #1
2
4
3
4
1
1
測資資訊:
記憶體限制: 64 MB
公開 測資點#0 (10%): 1.0s , <1K
公開 測資點#1 (10%): 1.0s , <1K
公開 測資點#2 (10%): 1.0s , <1K
公開 測資點#3 (10%): 1.0s , <1M
公開 測資點#4 (10%): 1.0s , <1M
公開 測資點#5 (10%): 1.0s , <1M
公開 測資點#6 (10%): 1.0s , <1M
公開 測資點#7 (10%): 1.0s , <1M
公開 測資點#8 (10%): 1.0s , <1M
公開 測資點#9 (10%): 1.0s , <10M
Hint :
Tags:
800 greedy strings
出處:
Codeforces Round #805 [管理者:
lamkinun@gma... (Kinda Lam)
]


ID User Problem Subject Hit Post Date
沒有發現任何「解題報告」