← Back to topics
Topic

z-zurka

k
koftriot12
Obviously it's an easy task but it doesn't work even for one test case and i don't know what's the problem.It works fine on my machine.


removed



A
Al3kSaNdaR
First error ->

scanf("%lldd",&a);


It should be ->

scanf("%lld",&a);


Edit -> That is why you get invalid memory reference.
d
dpetek

if(cityA[i1]==cityB[i2]==cityC[i3])


You can't compare 3 cities like that... This is equal to :

if(cityA[i1]==(cityB[i2]==cityC[i3]))

where :

cityB[i2]==cityC[i3]

is either true or false ( 0 or 1 ) ... And you always compare cityA[i1] with 0 or 1 ...
It should be:


if(cityA[i1]==cityB[i2] && cityA[i1]==cityC[i3])
A
Al3kSaNdaR
Listen, i got TLE when i first wrote it. Do you know Pascal ? Because I can give you code in pascal, that you may understand. I tried to solve it in C++ but it has some error. :S
k
koftriot12
It's ok it worked for all of them thanks again.

g
gigac
Crap...
I got a correct result on 12 tests, but not on the rest 8. Can someone look the code ?
Thanks :S
m
mbalunovic
Use longint type instead of integer.
g
gigac
It's the same...can someone look at my code and help me :(
d
dancsi
I really don't know what is wrong with my code... 5 test cases don't work :( Here is my code
#include <iostream>

using namespace std;
int main()
{
long long n1, n2, n3, a[1000], b[1000], c[1000], i, k=0, l, d, traz, mid;
bool nasao;
scanf("%lld", &n1);
for(i=0;i<n1;i++)
scanf("%lld", &a[i]);
scanf("%lld", &n2);
for(i=0;i<n2;i++)
scanf("%lld", &b[i]);
scanf("%lld", &n3);
for(i=0;i<n1;i++)
scanf("%lld", &c[i]);
sort(a, a+n1);
sort(b, b+n2);
sort(c, c+n3);
for(i=0;i<n1;i++)
{
traz=a[i];
l=0;
d=n2-1;
nasao=false;
while((d-l>0)&&(!nasao))
{
mid=(l+d)/2;
if(b[mid]>traz) d=mid-1;
if(b[mid]<traz) l=mid+1;
if(b[mid]==traz) nasao=true;
}
if(b[l]==traz)
nasao=true;
if(nasao)
{
l=0;
d=n3-1;
nasao=false;
while((d-l>0)&&(!nasao))
{
mid=(l+d)/2;
if(c[mid]>traz) d=mid-1;
if(c[mid]<traz) l=mid+1;
if(c[mid]==traz) nasao=true;
}
if(c[l]==traz)
nasao=true;
if(nasao)
k++;
}
}
printf("%lld", k);
return 0;
}