DMPG '18 S1 - Mimi and Types

View as PDF

Submit solution

Points: 5
Time limit: 2.0s
Memory limit: 128M

Authors:
Problem type

Mimi was writing code in C++. She was utilizing a std::tuple for some purpose. Because her definition of the data structure was very complicated, she did not want to type it every single time. So therefore she decided to use numbers to represent the type instead.

A type is valid if and only if it consists of

  • a single 0 only.
  • a single digit n (1n9) followed by exactly n valid types.

But soon, things got out of hand. Mimi wasn't sure whether some of her types were valid. Could you help her validate her types?

Constraints

For all subtasks:

S will be non-empty and will be at most 105 characters in length.

All characters in S will be digits.

Subtask 1 [5%]

S will only contain 0.

Subtask 2 [15%]

S will only contain 0 and 1.

Subtask 3 [80%]

No additional constraints.

Input Specification

The first and only line of input will contain a non-empty string S consisting only of digits, representing the type.

Output Specification

The output should contain Valid if the type is valid, and Invalid if the type is invalid.

Sample Input 1

Copy
2300040000

Sample Output 1

Copy
Valid

Sample Input 2

Copy
23000

Sample Output 2

Copy
Invalid

Sample Input 3

Copy
00

Sample Output 3

Copy
Invalid

Comments

There are no comments at the moment.