VaeKnt's blog

By VaeKnt, history, 13 months ago, In English

Hello — I am very new so I'm not sure if I'm not having proper etiquette — please inform me if I'm being rude etc.

The problem is about finding the numerical ID of a string. So A = 1, B = 2, etc. AA = 27 (since it goes to Z then it becomes AA — kind of like an excel sheet.)

I thought I solved this, my code is the first screenshot) - I just thought that the ID is: eg ABC — the 'A' spot is 26^2, and the value of A is 1, 'B' spot is the 26^1 spot, and the value of B is 2, etc. Just like a normal number so the ID would be ABC = 26^2*1 + 26^1 * 2 + 26^3 * 0.

I did this in C++ and my code is above. It passes all but 3 test cases. And these are very close to the cut off of BRUTMHYHIIZP = 10^16, and my answer and the output differ by 1.

Is this because of the pow() function that I used? Or am I just wrong?

P.s: I read the atcoder editorial and they "initialise" by 26^1 + 26^2 .... 26^l-1. where l is the length of the string and then go on to just count where along the list the specific string is and then add it to the sum above so I know we did it different ways (sort of).

I just don't know why mine is wrong. I've spent a lot of time on it, and even tried using round(pow()) but I don't know why it's still wrong

AtCoder's solution

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

| Write comment?