All submissions for this problem are available.
The task is simple! You have to form a given number n using following two operations.
- Append a digit d to current number. The cost of this operation is d (0<=d<=9)
- Append any "substring of current number" to the current number. The cost of this operation is zero
You start the process with an empty number and repeat one of the above 2 operations until you get the desired number. Print the minimum cost to form the given number.
First line will contain T (the number of test cases).
For each test case input is the number to be formed by the given operations.(The number can be very large).
Print the minimum cost needed to form the given number using the given two operations.
- 1 ≤ T ≤ 10
- 1 ≤ n ≤ 1010000
Input: 2 123 1212 Output: 6 3
|Tags||basic-prog, npl_nitw, nplq1602, string|
|Time Limit:||1 sec|
|Source Limit:||50000 Bytes|
|Languages:||C, CPP14, JAVA, PYTH, PYTH 3.6, PYPY, CS2, PAS fpc, PAS gpc, RUBY, PHP, GO, NODEJS, HASK, SCALA, D, PERL, FORT, WSPC, ADA, CAML, ICK, BF, ASM, CLPS, PRLG, ICON, SCM qobi, PIKE, ST, NICE, LUA, BASH, NEM, LISP sbcl, LISP clisp, SCM guile, JS, ERL, TCL, PERL6, TEXT, SCM chicken, CLOJ, FS|
Fetching successful submissions