Hi everyone. I'm getting the right answer on the first couple of test cases on a fairly easy problem but on the third one I get "time limit exceeded". Here's my submission: https://codeforces.net/contest/1325/submission/82660385 . If anybody can think of a way to make my solution more efficient it would help a lot!
Thank you very much.
Find in array is O(N) I think. You can use std::set (stores every element only once) and the size of the set should give you the answer you are looking for.
Thank you very much! I'm pretty new to c++ and I didn't know about std::set. It worked perfectly!
I know you have found your solution Just suggesting you some optimization techniques... 1. "using namespace std;" saves you from typing "std ::" before any library function 2. If you want to initialize every element of a particular array with 0 then you can write like this: int a[100]={0} or you may use it as global array as any global variable is initialized with 0 by default though it is recommended not to use global variables unnecessarily 3. Using only this header file: "#include<bits/stdc++.h>" saves you from writing numerous header files.It alone is enough for the other necessary header files.Pretty cool thing
Thanks man! Really helpful tips! I’ll start using them.