# Spam classification using neural net (SPAMCLAS)

``````#include <iostream>
#include <vector>

using namespace std;

int main ()
{
int T;
cin>>T;
while(T--)
{
unsigned long long N,min,max;
unsigned long long spammer=0,non_spammer=0,spam=0,non_spam=0;

cin>>N>>min>>max;

unsigned    long long weight[N],base[N];

for(unsigned long long i=0;i<N;i++)
{

cin>>weight[i]>>base[i];
}
#if 0
for(unsigned long long x=min;x<=max;x++)
{
int y=x;

for(int i=0;i<N;i++)
{
y=(weight[i]*y)+base[i];
}

if(y%2)
spam++;
else
non_spam++;

}

cout<<non_spam<<" "<<spam<<endl;

#else

int odd=0,even=0;

for(int i=0;i<=1;i++)
{	unsigned long long int y=i;
for(unsigned long long  j=0;j<N;j++)
{
y=(weight[j]*y)+base[j];
}
if(y%2 == 0)
even=even+1;
else
odd=odd+1;
}

if(odd == 2 )
{

spammer=1+max-min;

}
if(even==2)
{
non_spammer = 1+max-min;

}
if(even ==1 &&odd ==1)
{
if((1+max-min)%2)
{
spammer = ((1+max-min)/2)+1;
non_spammer = ((1+max-min)/2);
}
else
{
spammer = ((1+max-min)/2);
non_spammer = ((1+max-min)/2);

}

}
cout<<non_spammer<<" "<<spammer<<endl;

#endif

}

return 0;
}
``````

Hey guys ,
This is the code that i have written for this question but it is failing in sum cases i dont k now exactly at which case it is failing.

1 Like

1 Like

It seems to fail for e.g.

``````1
5 2 80
53 3
37 36
43 80
59 94
87 23
``````

Edit:

Smaller testcase:

``````1
3 10 10
11 45
7 73
43 16
``````
1 Like

hey can you share the ouput for this cases
in my case for first test case i got 40 39
and for second case i got 1 0

1 Like

I also get

``````40 39
``````

and

``````1 0
``````

but the code from your first post in this thread gives me:

``````39 40
``````

and

``````0 1
``````
1 Like

I have modified the code and you can this cases for the below code:

``````#include <iostream>
#include <vector>

using namespace std;

int main ()
{
int T;
cin>>T;
while(T--)
{
int N,min,max;
int spammer=0,non_spammer=0,spam=0,non_spam=0;

cin>>N>>min>>max;

int weight[N],base[N];

for(int i=0;i<N;i++)
{

cin>>weight[i]>>base[i];
}

#if 0

for(int x=min;x<=max;x++)
{
int y=x;

for(int i=0;i<N;i++)
{
y=((weight[i]*y)+base[i])%2;
}

if(y%2)
spam++;
else
non_spam++;

}

cout<<non_spam<<" "<<spam<<endl;

#else

int odd=0,even=0;

for(int i=0;i<=1;i++)
{	int y=i;
for(int j=0;j<N;j++)
{
y=(weight[j]*y)+base[j];
}
if(y%2 == 0)
even=even+1;
else
odd=odd+1;
}

if(odd == 2 )
{

spammer=1+max-min;

}
if(even == 2)
{
non_spammer = 1+max-min;

}
if(even ==1 &&odd ==1)
{

if(((min%2 ==0) && (max%2 == 1)) ||((min%2 ==1) && (max%2 == 0)))
{
non_spammer = ((1+max-min)/2);
spammer = ((1+max-min)/2);
}
if(((min%2 ==1) && (max%2 == 1)))
{
spammer = ((1+max-min)/2)+1;
non_spammer = ((1+max-min)/2);

}
if(((min%2 ==0) && (max%2 == 0)))
{
spammer = ((1+max-min)/2);
non_spammer = ((1+max-min)/2)+1;

}

}
cout<<non_spammer<<" "<<spammer<<endl;

#endif

}

return 0;
}
``````
1 Like

Your updated code now fails the following testcase:

``````1
1 3 3
3 39
``````

(answer should be `1 0`).

Hey i missed somelogic there but below code should work for all the cases:

``````#include <iostream>
#include <vector>

using namespace std;

int main ()
{
int T;
cin>>T;
while(T--)
{
int N,min,max;
int spammer=0,non_spammer=0,spam=0,non_spam=0;

cin>>N>>min>>max;

int weight[N],base[N];

for(int i=0;i<N;i++)
{

cin>>weight[i]>>base[i];
}

#if 0

for(int x=min;x<=max;x++)
{
int y=x;

for(int i=0;i<N;i++)
{
y=((weight[i]*y)+base[i])%2;
}

if(y%2)
spam++;
else
non_spam++;

}

cout<<non_spam<<" "<<spam<<endl;

#else

int odd=0,even=0;

for(int i=0;i<=1;i++)
{	int y=i;
for(int j=0;j<N;j++)
{
y=(weight[j]*y)+base[j];
}
if(y%2 == 0)
even=even+1;
else
odd=odd+1;
}

if(odd == 2 )
{

spammer=1+max-min;

}
if(even == 2)
{

non_spammer = 1+max-min;

}
if(even ==1 &&odd ==1)
{

if(((min%2 ==0) && (max%2 == 1)) ||((min%2 ==1) && (max%2 == 0)))
{
non_spammer = ((1+max-min)/2);
spammer = ((1+max-min)/2);
}
if(((min%2 ==1) && (max%2 == 1)))
{
spammer = ((1+max-min)/2);
non_spammer = ((1+max-min)/2)+1;

}
if(((min%2 ==0) && (max%2 == 0)))
{
spammer = ((1+max-min)/2)+1;
non_spammer = ((1+max-min)/2);

}

}
cout<<non_spammer<<" "<<spammer<<endl;

#endif

}

return 0;
}
``````

Seems to fail for

``````1
3 10 10
11 45
7 73
43 16
``````

for me (answer should be `1 0`).

Hey thank you for supporting me to solve this problem .

1 Like
``````#include <iostream>
#include <vector>

using namespace std;

int main ()
{
int T;
cin>>T;
while(T--)
{
int N,min,max;
int spammer=0,non_spammer=0,spam=0,non_spam=0;

cin>>N>>min>>max;

int weight[N],base[N];

for(int i=0;i<N;i++)
{

cin>>weight[i]>>base[i];
}

#if 0

for(int x=min;x<=max;x++)
{
int y=x;

for(int i=0;i<N;i++)
{
y=((weight[i]*y)+base[i])%2;
}

if(y%2)
spam++;
else
non_spam++;

}

cout<<non_spam<<" "<<spam<<endl;

#else

int odd=0,even=0;
int y_even_i_even=0,y_odd_i_odd=0,y_even_i_odd=0,y_odd_i_even=0;
for(int i=0;i<=1;i++)
{	int y=i;
for(int j=0;j<N;j++)
{
y=(weight[j]*y)+base[j];
}
if((y%2 == 0) && i ==0)
{
y_even_i_even=1;
even=even+1;
}
if((y%2 == 0) && i ==1)
{
y_even_i_odd=1;
even=even+1;
}
if((y%2 == 1) && i ==0)
{
y_odd_i_even=1;

odd=odd+1;
}
if((y%2 == 1) && i ==1)
{
y_odd_i_odd=1;

odd=odd+1;
}

}

if(odd == 2 )
{
spammer=1+max-min;

}
if(even == 2)
{

non_spammer = 1+max-min;

}
if(even ==1 &&odd ==1)
{

if(y_even_i_even ==1 || y_odd_i_odd==1)
{

if(max==min)
{
if(max%2==0)
{
spammer = 0;
non_spammer =1;
}
else
{
non_spammer = 0;
spammer = 1;

}
}

else if(((min%2 ==0) && (max%2 == 1)) ||((min%2 ==1) && (max%2 == 0)))
{
non_spammer = ((1+max-min)/2);
spammer = ((1+max-min)/2);
}
else if(((min%2 ==1) && (max%2 == 1)))
{
spammer = ((1+max-min)/2)+1;
non_spammer = ((1+max-min)/2);

}
else if(((min%2 ==0) && (max%2 == 0)))
{
spammer = ((1+max-min)/2);
non_spammer = ((1+max-min)/2)+1;

}

}

if(y_even_i_odd ==1 || y_odd_i_even==1)
{

if(max==min)
{
if(max%2==0)
{
spammer = 1;
non_spammer =0;
}
else
{
non_spammer = 1;
spammer = 0;

}
}

else if(((min%2 ==0) && (max%2 == 1)) ||((min%2 ==1) && (max%2 == 0)))
{
non_spammer = ((1+max-min)/2);
spammer = ((1+max-min)/2);
}
else if(((min%2 ==1) && (max%2 == 1)))
{
spammer = ((1+max-min)/2);
non_spammer = ((1+max-min)/2)+1;

}
else if(((min%2 ==0) && (max%2 == 0)))
{
spammer = ((1+max-min)/2)+1;
non_spammer = ((1+max-min)/2);

}

}

if(y_even_i_odd ==1 && y_odd_i_odd==1)
{
spammer=non_spammer=0;

}
if(y_even_i_even ==1 &&y_odd_i_even==1)
{
spammer=non_spammer=0;

}

}
cout<<non_spammer<<" "<<spammer<<endl;

#endif

}

return 0;
}
``````

In this code i have written the code by testing each case but still its showing wrong answer.

``````1
9 1 10
69 1
73 84
28 95
18 4
31 48
79 93
13 73
55 19
75 84
``````

``````#include <iostream>
#include <vector>

using namespace std;

int main ()
{
int T;
cin>>T;
while(T--)
{
int N,min,max;
int spammer=0,non_spammer=0,spam=0,non_spam=0;

cin>>N>>min>>max;

int weight[N],base[N];

for(int i=0;i<N;i++)
{

cin>>weight[i]>>base[i];
}

#if 0

for(int x=min;x<=max;x++)
{
int y=x;

for(int i=0;i<N;i++)
{
y=((weight[i]*y)+base[i])%2;
}

if(y%2)
spam++;
else
non_spam++;

}

cout<<non_spam<<" "<<spam<<endl;

#else

int odd=0,even=0,i;
int y_even_i_even=0,y_odd_i_odd=0,y_even_i_odd=0,y_odd_i_even=0;
for(i=0;i<=1;i++)
{	int y=i,u=i;
for(int j=0;j<N;j++)
{
y=(weight[j]*y)+base[j];
}
//cout<<"u="<<u;
if(!(y%2) && (u == 0))
{
y_even_i_even=1;
even++;
}
else if(!(y%2) && (u == 1))
{
y_even_i_odd=1;
even++;
}
else if((y%2 ) && (u == 0))
{
y_odd_i_even=1;

odd++;
}
else if((y%2) && (u ==1))
{
y_odd_i_odd=1;

odd++;
}

/*
if(y%2==0)
even++;
else
odd++;
*/

}

//cout<<"y_even_i_even="<<y_even_i_even<<"\ny_even_i_odd="<<y_even_i_odd<<"\ny_odd_i_even="<<y_odd_i_even<<"\ny_odd_i_odd="<<y_odd_i_odd<<endl;
//cout<<"odd="<<odd<<"\neven="<<even<<endl;
if(odd == 2 )
{
spammer=1+max-min;

}
if(even == 2)
{

non_spammer = 1+max-min;

}
if(even ==1 &&odd ==1)
{

if(y_even_i_even ==1 &&y_odd_i_odd==1)
{

if(max==min)
{
if(max%2==0)
{
spammer = 0;
non_spammer =1;
}
else
{
non_spammer = 0;
spammer = 1;

}
}

else if(((min%2 ==0) && (max%2 == 1)) ||((min%2 ==1) && (max%2 == 0)))
{
non_spammer = ((1+max-min)/2);
spammer = ((1+max-min)/2);
}
else if(((min%2 ==1) && (max%2 == 1)))
{
spammer = ((1+max-min)/2)+1;
non_spammer = ((1+max-min)/2);

}
else if(((min%2 ==0) && (max%2 == 0)))
{
spammer = ((1+max-min)/2);
non_spammer = ((1+max-min)/2)+1;

}

}

if(y_even_i_odd ==1 &&y_odd_i_even==1)
{

if(max==min)
{
if(max%2==0)
{
spammer = 1;
non_spammer =0;
}
else
{
non_spammer = 1;
spammer = 0;

}
}

else if(((min%2 ==0) && (max%2 == 1)) ||((min%2 ==1) && (max%2 == 0)))
{
non_spammer = ((1+max-min)/2);
spammer = ((1+max-min)/2);
}
else if(((min%2 ==1) && (max%2 == 1)))
{
spammer = ((1+max-min)/2);
non_spammer = ((1+max-min)/2)+1;

}
else if(((min%2 ==0) && (max%2 == 0)))
{
spammer = ((1+max-min)/2)+1;
non_spammer = ((1+max-min)/2);

}

}

if(y_even_i_odd ==1 &&y_odd_i_odd==1)
{
spammer=0;
non_spammer=0;

}
if(y_even_i_even ==1 &&y_odd_i_even==1)
{
spammer=0;
non_spammer=0;

}

}
cout<<non_spammer<<" "<<spammer<<endl;

#endif

}

return 0;
}
``````

check this one

1 Like

Looking good - passes all my randomised tests!

Edit:

Here’s my solution.

First successful solution, with Brute Force implementation and test generator: https://www.codechef.com/viewsolution/27468977

2 Likes

Hey thank you

1 Like

hey thanks i was having a similar doubt too.

1 Like