Issue
I'm trying to solve this problem: (https://codeforces.com/contest/1363/problem/A), and in my console when I give it the Input of the first example it outputs the right answer. but when submitting the code it says that my output was wrong and I dont know what's the problem. this is my code:
#include <iostream>
#include <vector>
#include <math.h>
#define endl '\n'
using namespace std;
bool solve(int sum, int n, int x, int i, vector<int> v)
{
if(x == 0)
return sum % 2 != 0;
bool c1, c2;
c1 = solve(sum + v[i], n, x - 1, i + 1, v);
if(i == n - 1 - x)
c2 = solve(sum, n, x, i + 1, v);
return c1 || c2;
}
int main()
{
fast;
int t;
cin >> t;
while(t--)
{
int n, x;
cin >> n >> x;
vector<int> v(n);
for(int i = 0; i < n; i++)
cin >> v[i];
if(solve(0, n, x, 0, v))
cout << "Yes" << endl;
else
cout << "No" << endl;
}
}
Solution
The behaviour can be different, because your code has Undefined Behaviour - variable c2
in function solve
can be used uninitialized.
Answered By - Kaznov Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.