ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

could anyone tell me how to solve MLE?
Posted by young master 15 Jun 2004 19:39
//my program's as follows
#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    long n,m,i,j,*p,*q,count=0;
    bool found;
    cin>>n;
    p=(long *)malloc(n*4);
    for(i=0;i<n;i++)
       cin>>*(p+i);
    cin>>m;
    q=(long *)malloc(m*4);
    for(j=0;j<m;j++)
    {
        cin>>*(q+j);
        found=binary_search(p,(p+n),*(q+j));
        if(found)
           count++;
    }
    cout<<count<<endl;
    return 0;
}
Re: could anyone tell me how to solve MLE?
Posted by Vlad Veselov 15 Jun 2004 23:13
Maybe, binary_search is recursive?
Re: could anyone tell me how to solve MLE?
Posted by encrypted_cx 16 Jun 2004 03:18
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
vector<int> a(0);
int m;
void init_solve() {

    cin>>n;
    int c;
    for(int i=0;i<n;i++) {
        cin>>c;
        a.push_back(c);
    }

    cin>>m;
    int br=0;
    for(int i=0;i<m;i++) {
        cin>>c;
        if(binary_search(a.begin(),a.end(),c)) br++;
    }
    cout<<br<<'\n';

}

int main() {

    init_solve();

    return 0;
}
Re: could anyone tell me how to solve MLE?
Posted by young master 18 Jun 2004 18:48
hey,friend,it's really kool,the <vector>, isn't it?:)
thanks for teaching me...