I am simulating excatly like the problem does, using a vector of stacks and poping elems after checking if the top mactches the elem as per sequence. My solution does not get accepted.
void solve_problems()
{
unsigned long int T = 0, N = 0;
long long int sum = 0, A = 0, B = 0, K = 0, M = 0;
std::cin >> T;
while (T–) {
sum = 0;
std::cin >> N;
std::deque<std::stack > stacks(N);
forl(i, 0, N) {
std::cin >> K;
sum = sum + K;
forl(j, 0, K) {
std::cin >> A;
stacks[i].push(A);
}
}
std::deque sequence(sum);
forl(j, 0, sum) {
std::cin >> sequence[j];
}
P = (a[1] + 1) * (a[2] + 1) * … (a[n] + 1) and P <= 10^6
Let’s try to maximize value of n greedily! We can do that replacing each a[i] with lowest possible value. (ie 1).
So now P = 2 * 2 * … (let say x terms)
so, P >= 2 ^ x
ie x <= log2§
No it cannot be solved by this method. Check the test case here :
1
2
2 1 4
2 1 4
4 1 1 4
the answer should be No but your code is giving Yes.Obviously the test cases are weak.
How do I solve test cases where there can be multiple matches and if choosing one match instead of other can result in ‘no’ but choosing another match results in ‘yes’ ?
Example:
first thread: 1 2
second thread: 2 3
2 3 2 1
Result is ‘yes’ but if I choose 2 from first thread instead of second results in ‘no’.
Another example:
First thread: 1 2 4
Second thread: 3 2 4 8
4 8 4 2 2 3 1
Result is ‘yes’ only if 4 from second thread is chosen on encountering first 4 in the sequence otherwise result comes out to be ‘no’, even though the sequence is valid.
How do I solve this?