FORMAT - HTML Formatting

Description

You have been given formatted text and asked to converted it HTML.
Each character may be formatted as bold, italic, underlined, or some combination.
In HTML, content between <b> and </b> tags is bold. Content between <i> and </i> tags is italic. Content between <u> and </u> tags is underlined.
What is the minimum number of properly nested HTML tags needed to produce a given format?
For example, say we wanted to format <i><b>LookAt</b>Me</i>!
  • <b><i>LookAt</b>Me</i>! has incorrectly nested tags.
  • <b><i>LookAt</i></b><i>Me</i>! has correctly nested tags, but is longer than necessary.
  • <i><b>LookAt</b>Me</i>! is the shortest and uses the fewest number of tags.

Input

There will be a sequence of 1 to 20,000 numerals. Each numeral denotes the formatting at that position.
  • 0 - no formatting
  • 1 - bold
  • 2 - italic
  • 3 - bold and italic
  • 4 - underlined
  • 5 - bold and underlined
  • 6 - italic and underlined
  • 7 - bold, italic, and underlined
(There is no need to actually specify the content, since that will not affect the answer.)
The example earlier would be given as 333333220.

Output

The minimum number of <b>, </b>, <i>, </i>, <u>, and </u> tags required.
Input Input Input Input
01
333333220
00110066
12364012375303657213412303
Output Output Output Output
2
4
6
54

Added by:BYU Admin
Date:2013-10-18
Time limit:1s-2.5s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64

hide comments
2014-07-07 11:21:27 Satyaki Upadhyay
@Avinash The tags need to be properly nested. So the order in which you insert opening or closing braces is important.
2014-01-13 14:57:46 Avinash
@Satyaki I'm also getting 8.
2014-01-09 13:58:38 Satyaki Upadhyay
@nitish answer for176751 should be 8 right?
b_iu_/b_b_/i_/u_/b
the underscores indicate character positions
2013-11-19 22:22:37 samfisher
@nitish I am getting 16 for your test case , any idea what i am doing wrong
2013-11-11 16:35:02 nitish rao
Check this one : 176751. Ans:14.
@anirudh: i was also getting 16. Thats why no AC yet. :(

Last edit: 2013-11-21 15:50:00
2013-11-05 11:22:21 Andrey Maksimenko
Mauro Persano: thank you, but this didn't help. Posted to forum. Will be appreciate for any ideas.
2013-11-04 21:36:02 Mauro Persano
Andrey Maksimenko: I read the input with scanf, but got WA until I trimmed invalid characters (not 0-7) at the end of the input string. That could be your problem.
2013-11-04 17:17:16 Andrey Maksimenko
I'm getting answer 54 for "12364012375303657213412303", but still WA, any tricky test cases please?
2013-10-31 21:20:51 :D
Note it must be properly nested.
2013-10-29 21:02:11 aman jain
how is the answer for case "12364012375303657213412303" is 54. I think it should be 44.
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.