let's take string abcd;
so you need to first check si<sj for full string if si<sj is 0 then ans is 0.
else
you need to exchange every element of string a to z;
@kashish i think in no minimum no maximum
i am missing boundary condition that's why i am getting wrong ans.
if you passed any single test in 2nd subtask then provide me answer for sample test case:
@kashish and @sj7 use this code to generate all subsequences
this print the all subsequences of any array.
then if you get all AC then tell me.
this code faster way to print all subsequnces.
/* C++ code to generate all possible subsequences.
Time Complexity O(n * 2^n) */
#include<bits/stdc++.h>
usingnamespace std;
void printSubsequences(int arr[], int n)
{
/* Number of subsequences is (2**n -1)*/
unsignedint opsize = pow(2, n);
/* Run from counter 000..1 to 111..1*/
for (int counter = 1; counter < opsize; counter++)
{
for (int j = 0; j < n; j++)
{
/* Check if jth bit in the counter is set
If set then print jth element from arr[] */
if (counter & (1<<j))
cout << arr[j] << " ";
}
cout << endl;
}
}
// Driver program
int main()
{
int arr[] = {1, 2, 3, 4};
int n = sizeof(arr)/sizeof(arr[0]);
cout << "All Non-empty Subsequences\n";
printSubsequences(arr, n);
return 0;
}
@Kashish After getting all subsequences,
what did you do ? am getting WA in every subtask! Only sample is running correctly.
After I got the subsequence I ran a loop and found if the length of the subsequence == k then sort this subsequence and ran another loop from 1 to k-1 and multiplied all integers??? Are we not supposed to do that ??
for eg if k= 5 and I got two subsequences like [1,2,3,4,5] and [2,4,5,6,7] then my result will be
@sc7 if you don't get first subtask then use this
MOD=1000000007
ans=((ans%MOD)*(a[i]%MOD))%MOD;
. i don't know why i am getting wrong answer in 2nd subtask
i think in 2nd subtask there may be corner cases which i am getting or subtask 1 test cases are too light ?
@ipg Can you tell me the complexity of your NMINMAX code? Because if you are generating all the subsequences then it is impossible to pass the second subtask as for the second subtask value n <=5000 and 2^5000 is surely not going to run.
@iamrahul
/* C++ code to generate all possible subsequences.
Time Complexity O(n * 2^n) */
google it you will find efficient solution to generate all subseq.
@ipg I really don't understand what are you talking about as there is no "efficient" way to generate all subsequences since the number of subsequences for an array length n is itself 2^n-1 excluding the empty array. You must be getting TLE in your second subtask if you have used this code:
/* C++ code to generate all possible subsequences.
Time Complexity O(n * 2^n) */
#include<bits/stdc++.h>
usingnamespace std;
void printSubsequences(int arr[], int n)
{
/* Number of subsequences is (2**n -1)*/
unsignedint opsize = pow(2, n);
/* Run from counter 000..1 to 111..1*/
for (int counter = 1; counter < opsize; counter++)
{
for (int j = 0; j < n; j++)
{
/* Check if jth bit in the counter is set
If set then print jth element from arr[] */
if (counter & (1<<j))
cout << arr[j] << " ";
}
cout << endl;
}
}
// Driver program
int main()
{
int arr[] = {1, 2, 3, 4};
int n = sizeof(arr)/sizeof(arr[0]);
cout << "All Non-empty Subsequences\n";
printSubsequences(arr, n);
return 0;
}