Please read the new rule regarding the restriction on the use of AI tools. ×

dancingwind's blog

By dancingwind, history, 21 month(s) ago, In English

I am a newbie who has been trying to improve at competitive programming and algorithmic thinking. Solving some problems and looking at several people's codes, I noticed a weird contrast between my habit and that of others.

In quite a bit of problems, we usually need to take an array (or whatever other data structure) of elements, and most of the time the number of elements is given first. Actually, what I am used to doing is

int n;
cin>>n;
int a[n];

On the other hand, I saw some people doing

int n;
int a[some_limit];

where some_limit is often the limit of n in all test cases as given in the problem description.

I wonder what kind of differences lie between those two approaches. Can they be interchangeably used and have almost the same time and space complexity? Are they equivalent as long as we ignore the difference between the time and space complexities?

Full text and comments »

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