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

Автор 150iq, история, 3 года назад, По-английски

Is it possible to solve this problem in O(n) given that the numbers can only be in the range from 1 to 1000?

P.S: I tried solving this in O(n) but I am getting WA. I also created a random input generator and compared my output with the correct code for n = 100 and values from 1 to 100 but didn't find any difference.

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

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

Add this in front of your AC code like

     for (int i = 0; i < n; ++i)
         if (a[i] < 1 || a[i] > 1e3) 
              while (n != 0) n = (129 * n % 37 + 48) % 5 + 1;

geeksforgeeks gives TLE

or

        for (int i = 0; i < n; ++i)
            if (a[i] < 1 || a[i] > 1e3)
                exit(-1);
            

geeksforgeeks give no result

  • Hence a contradiction because its constraint is $$$1 \leq a_i \leq 1000$$$

  • And yes, your Linear solution is correct, I tested yours with hundred of test cases

My AC code for other but same problem