Page 2 of 2

Re: sample test cases 11849 cd

Posted: Wed Jul 04, 2012 11:26 pm
by diegon
Is good to know that the disks id go up to 2 000 000. Just checked. :D

Re: Judge not judging (11849 - CD)

Posted: Mon Jul 23, 2012 7:13 pm
by AhmadKhatar
Hi!
How can I speed up the code?
Thanks in advance!

Re: Judge not judging (11849 - CD)

Posted: Fri Feb 01, 2013 10:22 pm
by brianfry713

Re: sample test cases 11849 cd

Posted: Thu Jan 09, 2014 2:22 pm
by uDebug
brianfry713,

Thanks very much for these test cases.

11849 - CD

Posted: Sun Feb 23, 2014 10:17 pm
by me33
Getting run time error. :cry: :(
plz help...
my code.

Code: Select all

removed after AC. :D  :) 

Re: 11849 - CD Why RTE???

Posted: Tue Feb 25, 2014 12:49 am
by brianfry713
I think you could make your arrays global, fixed size, and int to avoid RE, but then you'll probably get TLE. See the other threads on this problem. You can solve it in O(N + M) instead of O(N * M). Also scanf/printf is faster than cin/cout.

Re: 11849 - CD Why RTE???

Posted: Fri Feb 28, 2014 2:04 am
by me33
Thanks brianfry713

Re: 11849 - CD Why WA?

Posted: Fri Sep 12, 2014 8:45 am
by sajal2k8
Why i am getting wrong answer? Here is my code:

Code: Select all

#include <iostream>

using namespace std;
 long long int nu[1000000],num[1000000];

 long long int matchCounter( long long int lottery[5],  long long int user[5],  long long int matches,  long long int SIZE)
{
     long long int count = 0;

    for (int count = 0; count < SIZE; count++)
    {
        if (lottery[count] == user[count])
        {
            matches++;
        }
}

    return matches;
}
int main()
{
     long long int a,b,c,i,j,sum=0;
    while(cin>>a>>b && (a!=0 || b!=0))
    {
        for(i=0;i<a;i++)
            cin>>nu[i];
        for(j=0;j<b;j++)
            cin>>num[j];

        if(a<b)
            c=a;
        else
            c=b;
        sum=matchCounter(nu,num,sum,c);
        cout<<sum<<endl;
        sum=0;
    }
    return 0;
}
Thanks in advance :)

Re: 11849 - CD

Posted: Fri Sep 12, 2014 10:53 pm
by brianfry713
Input:

Code: Select all

2 1
1
2
2
0 0
output should be 1

Re: 11849 - CD

Posted: Sat Oct 17, 2015 2:51 am
by amrondonp
Just use 2 pointers instead a map.

Suppose we have 2 arrays sorted

a1 a2 ... an-1
b1 b2 ... bm-1

start with ans=0
and
pa=0 and pb=0 the indexes

if( a[pa] == b[pb] ) ans++

then you just advance the pointer in the array which has the least number (if they are equal no matter which you choose)
repeat whis while pa<n and pb<m