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

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

How to take fast I/O in C++? I am solving a problem where number of test cases can be 10^6 so i guess fast I/O will help to speed up my solution.

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

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

    +1 but sometimes it's not enough

    Another possible way is to implement your own reader for integer/real/signed types using getchar():

    int next_int() {
      char c;
      do { c = getchar(); } while( c != '-' && !isdigit(c) );
      bool neg = (c == '-');
      int result = neg ? 0 : c - '0';
      while( isdigit(c = getchar()) )
        result = 10 * result + (c - '0');
      return neg ? -result : result;
    }
    

    In most cases coders use it to get top1 by execution time))

    But in case N = 10^6 it may be useful to beat TL with solution that wasn't intended by jury.

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

      Thanks it did reduce my time but still TLE. I guess i have to improve my algo.