PluCodeGenerator
SRM 255 · 2005-07-28 · by Andrew_Lazarev
Problem Statement
You are creating a storage management system. This system should create new PLU codes for new items. The requirements state that a PLU code must be a positive integer that does not contain three consecutive equal digits. For example, PLU codes 11211, 73399, 655 and 30 are valid PLU codes, but 11111, 73339, 555 and 3000 are invalid (they contain 111, 333, 555 and 000 respectively). For statistical purposes you want to count the number of invalid PLU codes.
You will be given an
Constraints
- N will be between 1 and 1000000000, inclusive.
111 Returns: 0
The first invalid PLU code is 111, so there are no invalid PLU codes less than 111.
556 Returns: 5
The invalid PLU codes less than 556 are 111, 222, 333, 444 and 555.
1113 Returns: 13
The invalid PLU codes less than 1113 are 111, 222, 333, 444, 555, 666, 777, 888, 999, 1000, 1110, 1111 and 1112.
7346556 Returns: 323647
11 Returns: 0
Submissions are judged against all 103 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class PluCodeGenerator with a public method int countInvalidCodes(int N) · 103 test cases · 2 s / 256 MB per case