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

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

I was solving "Digit sum" problem of Atcoder DP contest. I am just curious why my two solutions have such a vast difference in their execution time.

My First solution which took more than 2000ms (https://atcoder.jp/contests/dp/submissions/24396061)

My Second solution which took less than 200ms (used global variables) (https://atcoder.jp/contests/dp/submissions/24396078)

Just adding some more parameters to a function completely changed the time complexity, strange isn't it?

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

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

Auto comment: topic has been updated by Kmare (previous revision, new revision, compare).

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

Cause you're not passing the string by reference in the first solution. In state function, change "string s" to "string& s" and you'll see a similar execution time

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

Everytime a new copy of the string gets created since you pass by value, do pass by reference, I think it will run in similar time.