Iam17YearsOld's blog

By Iam17YearsOld, history, 3 years ago, In English

I've seen most programmers, when they declare an array globally, they take some extra spaces. for example, if the question asks for a 10^7 sized array they declare like this :

const int N = 1e7+10
int a[N]

why 10 extra spaces?

  • Vote: I like it
  • +6
  • Vote: I do not like it

| Write comment?
»
3 years ago, hide # |
 
Vote: I like it +14 Vote: I do not like it

When you do some operations on arrays which involve complicated indices (such as DP recursions), you can and often will access some index that is beyond $$$n$$$, such as $$$n+1$$$ or $$$n+2$$$. Usually it's just quicker to just add an arbitrary +5 or +10 than to calculate the exact number of extra spaces you need in the array.

(I personally don't do this +5/+10 thing, because I feel that this makes me lazy in thinking, but oh well, lots of people are doing it and they're just fine.)

»
3 years ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

it just feels good

»
3 years ago, hide # |
 
Vote: I like it +6 Vote: I do not like it

It gives you +10 extra CF rating

  • »
    »
    3 years ago, hide # ^ |
     
    Vote: I like it +21 Vote: I do not like it

    omg sir, so if I do

    int a[1000000 + 10000];
    

    will I become legendairy glandmaster and beat tourists on Codeforce??!1!1

    • »
      »
      »
      3 years ago, hide # ^ |
       
      Vote: I like it +5 Vote: I do not like it

      You can get a maximum of 10 points for each problem you submit, but be cautious because a +10 in the array can also decrease your rating by 10 if you submited it wrong.

      So make sure you choose them carefully