solution link: https://ideone.com/Dn2nQN problem link : https://codeforces.net/problemset/problem/1234/B2 Why it is giving tle at 23rd case?
# | User | Rating |
---|---|---|
1 | tourist | 3985 |
2 | jiangly | 3814 |
3 | jqdai0815 | 3682 |
4 | Benq | 3529 |
5 | orzdevinwang | 3526 |
6 | ksun48 | 3517 |
7 | Radewoosh | 3410 |
8 | hos.lyric | 3399 |
9 | ecnerwala | 3392 |
9 | Um_nik | 3392 |
# | User | Contrib. |
---|---|---|
1 | cry | 169 |
2 | maomao90 | 162 |
2 | Um_nik | 162 |
4 | atcoder_official | 161 |
5 | djm03178 | 158 |
6 | -is-this-fft- | 157 |
7 | adamant | 155 |
8 | awoo | 154 |
8 | Dominater069 | 154 |
10 | luogu_official | 151 |
solution link: https://ideone.com/Dn2nQN problem link : https://codeforces.net/problemset/problem/1234/B2 Why it is giving tle at 23rd case?
Name |
---|
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.net/blog/entry/62393
okk thank you!
Unordered map can have a high complexity when it is used a lot of times.
ohhkk