11849 - CD

All about problems in Volume 118. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

diegon
New poster
Posts: 3
Joined: Fri Jun 08, 2012 10:45 pm

Re: sample test cases 11849 cd

Post by diegon »

Is good to know that the disks id go up to 2 000 000. Just checked. :D
AhmadKhatar
New poster
Posts: 28
Joined: Fri Mar 30, 2012 12:57 am

Re: Judge not judging (11849 - CD)

Post by AhmadKhatar »

Hi!
How can I speed up the code?
Thanks in advance!
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: Judge not judging (11849 - CD)

Post by brianfry713 »

Check input and AC output for thousands of problems on uDebug!
uDebug
A great helper
Posts: 475
Joined: Tue Jul 24, 2012 4:23 pm

Re: sample test cases 11849 cd

Post by uDebug »

brianfry713,

Thanks very much for these test cases.
Check input and AC output for over 7,500 problems on uDebug!

Find us on Facebook. Follow us on Twitter.
me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

11849 - CD

Post by me33 »

Getting run time error. :cry: :(
plz help...
my code.

Code: Select all

removed after AC. :D  :) 
Last edited by me33 on Fri Feb 28, 2014 2:03 am, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11849 - CD Why RTE???

Post 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.
Check input and AC output for thousands of problems on uDebug!
me33
New poster
Posts: 16
Joined: Wed Feb 19, 2014 10:08 pm

Re: 11849 - CD Why RTE???

Post by me33 »

Thanks brianfry713
sajal2k8
New poster
Posts: 16
Joined: Mon Nov 18, 2013 5:15 pm

Re: 11849 - CD Why WA?

Post 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 :)
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11849 - CD

Post by brianfry713 »

Input:

Code: Select all

2 1
1
2
2
0 0
output should be 1
Check input and AC output for thousands of problems on uDebug!
amrondonp
New poster
Posts: 5
Joined: Fri Apr 03, 2015 2:29 am

Re: 11849 - CD

Post 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
Post Reply

Return to “Volume 118 (11800-11899)”