Search code examples
c++setunordered-set

Unordered_set not working on codechef ide


"unordered_set" is not working properly on codechef and giving wrong output on its online ide whereas I am getting right output on geeksforgeeks ide and codeblocks for Input like 3 2 10 1 100 4 3 i am getting 4 rows as expected in codeblocks and geeksforgeeks because n+m-1 is 4 whereas I am getting only 2 rows in codechef what can be the reason behind and now how it will work on codechef?

#include<stdio.h>
#include<bits/stdc++.h>
#include<unordered_set>
using namespace std;
int main()
{
int n,m,c=0,d,i,j,sum;
int a[10000];
int b[10000];
unordered_set <int> s;
scanf("%d %d",&n,&m);
for(i=0;i<n;i++)
    scanf("%d",&a[i]);
for(i=0;i<m;i++)
    scanf("%d",&b[i]);
for(i=0;i<n;i++)
{
    for(j=0;j<m;j++)
    {
        sum=a[i]+b[j];
        if(s.find(sum)==s.end())
        {
            s.insert(sum);
            printf("%d %d\n",i,j);
            c++;
        }
        if(c>=(n+m-1))
            {d=1;break;}
    }
    if(d==1)
        break;

}
}

Solution

  • Your program exhibits undefined behavior, by way of accessing the value of an uninitialized variable d.