|
|
back to boardWhy I had TL on4-th test? Posted by oli666 23 Feb 2009 15:34 My solution is: #include <iostream> //#include <conio.h> using namespace std; int prepod[15000], n; int binsearch(int num) { int l = 0, r = n - 1, m; while (r - l > 1) { int m = (r + l) / 2; if (prepod[m] == num) return 1; if (prepod[m] > num) l = m; if (prepod[m] > num) r = m; } if ((prepod[l] != num) && (prepod[r] != num)) return 0; else return 1; } int main() { int m, student, s=0; cin>>n; for (int i = 0; i < n; i++) scanf ("%i", &prepod[i]); cin>>m; for (int i = 0; i < m; i++) { scanf ("%i", &student); s+=binsearch (student); } cout<<s; //getch(); return 0; } And it has time O(mlogn) and it is about 9e+6. |
|
|