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

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

In Problem D for the first test case (last case)
6 1 6 3 4 5 6 My answer was 10 everywhere (I tried on VsCode, GFG ide, Codechef ide) but when I was submitting it on Codeforces it was showing 16 and it wasted all of my time. Can Anyone please tell me what could be the probable reason?

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

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

It'll be easier if you add submission link as well

»
3 года назад, # |
  Проголосовать: нравится +6 Проголосовать: не нравится
for (ll i = n; i >= 0; i--)

Just change this to

for (ll i = n; i >= 1; i--)

Since your array is 1 index based it just carrying value to 0 index and also during addition loop it is getting added to your answer , i resubmitted the corrected code but it failed on Case 2

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

    Thank You callmepandey for pointing it out. But then how on all local ide (Vs code,gfg ide, etc...) it was showing 10.

    All the time I was resubmitting it and getting WA and got ruined my contest.

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

      Yes that's what i am thinking , for these kind of cases i prefer codechef ide, Actually yesterday even my G was giving correct on my Machine but WA in test 1 in Codeforces later i found that i actually haven't initialised values to one of my array , I guess local ide consider non initialised arrays value as 0 where this is not the case of Codeforces and other Judges.

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

      When local variables are not initialised, a garbage value is stored. Since you are declaring your array locally, some garbage value is present at index 0. Since this is garbage, it differs in different platforms.

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

For the hundreds of such doubts that have preceded and will follow: the compiler is not buggy. It's always undefined behaviour.