When submitting a solution in C++, please select either C++14 (GCC 6-32) or C++17 (GCC 7-32) as your compiler. ×

NafisAlam's blog

By NafisAlam, 13 months ago, In English

Can someone help me understand the time complexity of submission #1 and #2? I don't understand why I got TLE on submission #1.

problem link : 1714E - Add Modulo 10

TLE submission #1 : 191420410

TLE submission #2 : 191295823

Thanks for your help.

  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?
»
13 months ago, # |
Rev. 2   Vote: I like it +5 Vote: I do not like it
      cin >> a[i];
      if(a[i] % 2 == 1) a[i] += a[i] % 10;
      while(a[i] < 10) a[i] += a[i] % 10;

This code will enter an infinite loop when the input is 0.

This is correct:

      cin >> a[i];
      if(a[i] % 2 == 1) a[i] += a[i] % 10;
      while(a[i] < 10 && a[i] != 0) a[i] += a[i] % 10;