viking37236's blog

By viking37236, history, 2 hours ago, In English

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

  • Vote: I like it
  • 0
  • Vote: I do not like it

»
63 minutes ago, # |
  Vote: I like it 0 Vote: I do not like it

Sliding window. Left window first , right second. From 1 to n. Choose best.

  • »
    »
    53 minutes ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    bs, if you dont know dont spread misinformation.