Unpleasant pairs of digits
Practice
2.3 (7 votes)
Binary search
Implementation
Dynamic programming
Algorithms
4d dynamic programming
Problem
86% Success 358 Attempts 30 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Alice has a set of \(N\) unpleasant pairs of digits.

Consider a number bad if it satisfies the following conditions:

  • Contains a pair of digits that goes in a row
  • It is unpleasant

Otherwise, the number is considered good.

Your task is to determine \(K\) ascending good numbers.

Input format

  • The first line contains one integer \(T\) that denotes the number of test cases.
  • The first line of the test case contains two integers \(N\) and \(K\).
  • The next \(N\) lines contain two digits \(d_1,d_2\).

Output format

Print \(T\) lines. The \(i^{th}\) line must contain an answer for the \(i^{th}\) test case.

Note: If answer is more than \(5\times10^{18}\), print -1.

Constraints

\(1≤ T≤ 1000 \)

\(0≤ n<100\)

\(0≤ d_1,d_2≤ 9\)

\(1≤ K≤ 10^{18}\)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
3 votes
Tags:
AlgorithmsBitmaskDynamic ProgrammingDigitDP4D dynamic programming
Points:30
Tags:
Medium
Points:30
3 votes
Tags:
MediumAlgorithmsMathematicsOpenApprovedGame Theory