shivam_sax's blog

By shivam_sax, 5 years ago, In English

Can anyone tell me why my code for problem D fails at tc 49 ? https://codeforces.com/contest/1185/submission/56065088

  • Vote: I like it
  • 0
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

The only thing which you missed was in the last check when you successively removed and checked if this element was the one to be deleted, you only checked that a[i] + d != a[i + 1] and a[i] + d == a[i + 2] then this is our potential element and if there is only one such index then it is our answer, the case may be that a[i] + d != a[i + 1] and a[i] + d != a[i + 2], such as the sequence [-1 -2 -3 -4 -5 -5 -5 -5 -6], when you look at index 4 (0-based indexing) you see index 5 (-5) is not -5 — 1 (= -6), but you see that the 6th index (-5) is also not -5 — 1 (so removing the element at index 5 doesn't do good and keeping it too doesn't, as the d was assumed -1, and in either case of inclusion or exclusion of index 5 the answer doesn't exist, hence the Jury's solution). Also make sure not to check the element you assumed to be the answer if your if() holds true in the next iteration (like you got i + 1 is the potential answer, you remove it so do i += 2 here, so as to avoid cases like TC 15).

I tried the above approach, and it passed (Solution)