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

Автор mathturbator, история, 11 лет назад, По-английски

These are links to my 2 submissions: 1) http://mirror.codeforces.com/contest/588/submission/13653807 2) http://mirror.codeforces.com/contest/588/submission/13653815

Only difference between both is that in 1) am using scanf to take input while in 2) am using cin. Although my logic remains the same, I got TLE and possible penalty (if this had happened during contest). Just because I used cin, does it make my submission wrong? If not, should time limits be set such that solutions are not rejected on usage of cin?

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

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

Tips to speed up cin Use std::ios_base::sync_with_stdio(false); and you'll be fine. Also, avoid using endl when you can use '\n'. Old compilers may slow cin down a little, always submit using C++11 if issues persist. Hope this helps!

  • »
    »
    11 лет назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I tried with C++11 and it still gave me TLE. And while I know that cin is slower than scanf, and that using scanf or your tips would be a better choice and help me accept my solution, but my point was if it is ok to judge a solution wrong just because you used a slower input method which itself is not so outdated or "not used anymore".

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

      The issue with setting time limits so that 'vanilla' cin will be fast enough is the possibility of allowing unintended solutions to pass if they are written with scanf (for example, an O(N^2) solution passing where an O(NlogN) solution is desired).

      Yes, it sucks if you have a good solution that TLEs due to slow i/o. But generally, people will make this mistake once and then learn how to avoid it. Meanwhile, relaxed time limits that allow unintended solutions to pass have a much more significant negative impact on contest quality.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

The speed of cin is just as fast as scanf if you include the following at the beginning of your main method:

ios_base::sync_with_stdio(0);
cin.tie(NULL); cout.tie(NULL);

To speed cin up even faster, prevent it from flushing the output stream for each new line by using #define endl '\n'.

»
11 лет назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

I don't understand the debate. Can you show me one problem in Codeforces which is not solvable with scanf and printf? Though there are often posts like this, got TLE with cin even after synced with stdio false and blah blah.... Why not always use scanf/printf, particularly when there can be as many as 10^6 numbers in the input? Why does it matter which is faster? I have yet to solve a problem where scanf/printf gets TLE but on the other hand cin/cout gets accepted.

Just use scanf/printf whenever the input is huge or you have doubts.