Блог пользователя ppastram

Автор ppastram, история, 4 года назад, По-английски

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.

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
4 года назад, # |
  Проголосовать: нравится +9 Проголосовать: не нравится

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.

  • »
    »
    4 года назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    Thank you very much! I'm pretty new to c++ and I didn't know about std::set. It worked perfectly!

»
4 года назад, # |
Rev. 3   Проголосовать: нравится +4 Проголосовать: не нравится

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