#2327590

Solution for ALDS1_4_B: Binary Search by pasta_az

Source Code Status Test Cases
    Policy: public     Reviewed: 15    
00.03 sec    3452 KB    27 lines     436 bytes    2017-05-20 03:35
#include<bits/stdc++.h>
using namespace std;
int n,q,s[100010],cnt;
int srch(int key){
  int left=0,right=n;
  while(left<right){
    int mid=(left+right)/2;
    if(s[mid]==key) return 1;
    if(s[mid]<key) left=mid+1;
    else right=mid;
  }
  return 0;
}
int main(){
  cin>>n;
  for(int i=0;i<n;++i) cin>>s[i];
  cin>>q;
  for(int i=0;i<q;++i){
    int key;
    cin>>key;
    if(srch(key)) ++cnt;
  }
  cout<<cnt<<endl;
  return 0;
}


Compile Error Logs:
You are not authorized to see the message.

Status
Judge: 10/10 C++ CPU: 00.03 sec Memory: 3452 KB Length: 436 B 2017-05-20 03:35 2017-05-20 03:35
Results for testcases
Case # Verdict CPU Time Memory In Out Case Name
Case #1: : Accepted 00.00 sec 2980 KB
Case #2: : Accepted 00.00 sec 3088 KB
Case #3: : Accepted 00.00 sec 2984 KB
Case #4: : Accepted 00.00 sec 3088 KB
Case #5: : Accepted 00.00 sec 3068 KB
Case #6: : Accepted 00.00 sec 3092 KB
Case #7: : Accepted 00.00 sec 2988 KB
Case #8: : Accepted 00.00 sec 3020 KB
Case #9: : Accepted 00.00 sec 3124 KB
Case #10: : Accepted 00.03 sec 3452 KB
< prev | / | next >  
 
Judge Input #  ( | ) Judge Output #  ( | )


Comments
 
 Under Construction.
 
Categories
 
 
Free Tags