PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, August 16, 2022

[FIXED] When submitting to Codeforeces output isn't the same as in the console

 August 16, 2022     c++, output     No comments   

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)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing