Need idea to solve this question.

Revision en1, by viking37236, 2024-09-05 08:54:26

Given an array A of N digits, and numbers M1, M2.

Let Conc(A) be the number formed by concatenating the digits in array A. Let Len(A) be the number of digits in A.

Example: for A = [1,3,2], Conc(A) = 132 and Len(A) = 3

Your task is to divide array A into two disjoint non-empty subsequences (X, Y) such that following conditions hold true

Conc(X) is a multiple of M1

Conc(Y) is a multiple of M2

Of all possible divisions, find the minimum value of abs( Len(X) — Len(Y) ), if there is no such possible division then print "-1".

Constraints: 1 <= N, M1, M2 <= 40 1 <= A[i] <= 9

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en1 English viking37236 2024-09-05 08:54:26 653 Initial revision (published)