### devit121's blog

By devit121, history, 7 weeks ago,

I've been trying to do this problem, but it keeps failing on the 2nd test on my computer it gives the correct answer, but when I try to submit it fails. I tried to work around that test case and failed on the 3rd one so what am I doing wrong? It's standard input/output. here's my code:

also, this is my first post so I apologize if some janky sh!t happens

• 0

 » 7 weeks ago, # |   0 Auto comment: topic has been updated by devit121 (previous revision, new revision, compare).
 » 7 weeks ago, # | ← Rev. 3 →   0 First, submit to us.
•  » » 7 weeks ago, # ^ | ← Rev. 2 →   0 I already did test 2 test 3
•  » » » 7 weeks ago, # ^ | ← Rev. 5 →   0 PS. This is how link is usually given: submission Hm, interesting. Why this submission is not in your submission pool? Are you doing Virtual Contest?PS. Ah! Now I know — I should have pressed "Show unofficial" checkbox to see your submissions.
•  » » » » 7 weeks ago, # ^ | ← Rev. 2 →   0 Are you trying to say that 'uninitialized value usage' is causing all my problems? or I'm just not able to understand PS. No, I'm not doing a virtual contest
•  » » » » » 7 weeks ago, # ^ | ← Rev. 4 →   0 Since we found your submission, its ok.
•  » » » » » » 7 weeks ago, # ^ |   0
•  » » » » » » » 7 weeks ago, # ^ | ← Rev. 3 →   0 In c++ you can use string data type for variable s. Don't use char* — you'd need to manage it in c-style, and it shouldn't be of length ASCII_SIZE — problem states that n is up to 10^5.
•  » » » » » » » » 7 weeks ago, # ^ |   0 Alright thanks
•  » » » » » » » » » 7 weeks ago, # ^ | ← Rev. 2 →   0 And ofcourse, your logic (cnt*cnt)+(b-cnt) is wrong — try to make few examples on a paper. 6 4 AABBCC would give you 4+(4-2), but the answer should be 8.
•  » » » » » » » » » 7 weeks ago, # ^ |   0 Nice. And to add: since n < 10^5 you don't need ll in map. And since you are counting only ASCII letters (big letters to be precise) it's enough to use vector v(26,0) — it works faster — thought it's not a problem here, making it your habit will help you latter.
 » 7 weeks ago, # |   0 It's because if you declare s[ASCII_SIZE] as a local variable, so the values in s[ASCII_SIZE] are uninitialized which could contain any random values. Meanwhile you read the string char by char, which means it's not guaranteed that your string ends with '\0' (null character = 0). If you use C-string (string with form of array of char), you should always ensure that it ends with '\0' as the terminating character.In strlen(str), it tries to find '\0' but character '\0' could not be found and it ends up reading an uninitialized memory. That's why you got Error #1: UNINITIALIZED READ in strlen(str).You could move s[ASCII_SIZE] as global variable, so all chars will be initialized to '\0'. Or, you can read a string by cin >> s, because as I know it will automatically add null terminated to the end of the string.