solution link: https://ideone.com/Dn2nQN problem link : https://codeforces.me/problemset/problem/1234/B2 Why it is giving tle at 23rd case?
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 3993 |
2 | jiangly | 3743 |
3 | orzdevinwang | 3707 |
4 | Radewoosh | 3627 |
5 | jqdai0815 | 3620 |
6 | Benq | 3564 |
7 | Kevin114514 | 3443 |
8 | ksun48 | 3434 |
9 | Rewinding | 3397 |
10 | Um_nik | 3396 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 155 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
10 | djm03178 | 152 |
solution link: https://ideone.com/Dn2nQN problem link : https://codeforces.me/problemset/problem/1234/B2 Why it is giving tle at 23rd case?
Название |
---|
Most likely it is because you are using an unordered map. Some tests are made specifically to mess with that container. Try using a map instead.
Yeah it worked thanks ! but why was it not working with unordered map. they are faster right?
Unordered maps are faster? Can you tell me why this is so in the first place?
In map data is stored in sorted order while in unordered map it is not. operations like insert delete takes log n in map while o(1) in unordered
Are you sure operations in Unordered Map takes O(1)?
i am just a beginner. i have studied o(1) for unordered map in general. can you please tell me why map wprking instead of ump
Read this: https://en.m.wikipedia.org/wiki/Hash_table
And share this with every programmer who programs without reading the manual.
In average case its O(1) atleast read what you are sending
On average != Worst case. Read again.
yup but most of the times its O(1). i think this test case was made to avoid ump as lot of collisions is happening but still using ump is better than map right?
yup but most of the times its O(1). i think this test case was made to avoid ump as lot of collisions is happening
You just contradicted yourself and answered your original question yourself.
using ump is better than map right?
You cannot generalize stuff this way. One obvious example, how do you get the minimum/maximum element in the hash table efficiently?
ok i got your point thanks
If you want more information on unordered_map and how to make it faster: https://codeforces.me/blog/entry/62393
okk thank you!
Unordered map can have a high complexity when it is used a lot of times.
ohhkk