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

Помогите time limit wa8
Posted by NikolosAvr 4 Nov 2014 00:39
#include <iostream>

int main()
{
 long int i, n, m, z, s, k, a[16000], l, r, mid;
 std::cin >> n;
 k=0;
 for (i=0; i<n; i++)
 {
  std::cin >> z;
  if ((i!=0) && (z!=a[k]))
  {
   a[k]=z; k++;
  }
  if (i==0)
  {
   a[k]=z; k++;
  }
 }
 n=k-1;
 std::cin >> m;
 s=0;
 k=0;
 for (i=0; i<m; i++)
 {
  l=0; r=n; k=0;
  std::cin >> z;
  if ((z>a[0]) && (z<a[n]))
   while ((l<r) && (k<n-1))
   {
    k=k+1;
    mid=(l+r)/2;
    if (a[mid]>z)
     r=mid;
     else if (a[mid]<z)
     l=mid;
     else if (a[mid]==z)
      break;
   }
  else if ((z==a[0]) || (z==a[n]))
   s++;
  if ((a[mid]==z) && (mid!=0))
   s++;
 }
 std::cout << s;
}
Re: Помогите time limit wa8
Posted by Sonechko 6 Feb 2015 20:26
Твоя программа слишком долго работает