Hello there,
I was solving problem 2001D and I came up to pretty straightforward conclusion that explore all permutations and output the lexicographically smallest one. Now, when I implemented this in code, it didn't work.
Code
Any help will be deeply appreciated!
Auto comment: topic has been updated by MAieshAdnan (previous revision, new revision, compare).
There is a significant difference between the concepts of a $$$Subsequence$$$ and a $$$Permutation$$$ of a given array. In this problem, the final answer must include all unique elements present in the array. However, not every permutation of the array can be derived as a subsequence of the original array.
For example, consider the following test case:
5
1 3 2 3 3
We know that the final answer will include three elements: 1, 2, and 3. Some permutations of the array
{1, 3, 2}
(referred to asa
in your code) cannot be valid answers because they cannot be extracted as subsequences, such as{3, 2, 1}
. In contrast, only the permutations{1, 3, 2}
and{1, 2, 3}
can be subsequences of the original array.Finally, regardless of the code's logic, its complexity is very high since generating all permutations of an array has a time complexity of $$$O(n!)$$$, where $$$n$$$ is the size of this array.
Need help with the following problem :
Given an array of n integers. Count the number subsequence whose product is divisible by k. Return answer modulo 1E9 + 7.
1 <= n <= 1E5 1 <= k < 1E9 1 <= a[i] <= 1E9
I think idea is use to prime factorization but I am not able to get it completely.