Can anyone please explain why my second solution is getting tle ?
I just used push_front() instead of push_back() here.
First Solution — 188254737
Second Solution — 188254960
Problem — 1527E - Partition Game
Thanks in advance.
# | 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 | 150 |
Can anyone please explain why my second solution is getting tle ?
I just used push_front() instead of push_back() here.
First Solution — 188254737
Second Solution — 188254960
Problem — 1527E - Partition Game
Thanks in advance.
Name |
---|
I took a quick look at the source code for libstdc++, but I couldn't really figure out a concrete version one would be faster than the other. In the source code, deques start empty, so
push_front
allocates a block at the front andpush_back
allocates a block at the back. However, I think this should be basically the same speed.For testing on my own, I wrote the following program:
Running this with
push_back
five times, the times I get are: - 374ms - 358ms - 358ms - 358ms - 436msWith
push_front
, I get: - 514ms - 483ms - 436ms - 405ms - 529ms(I also modified some other comment to produce new runs for each program)
So it seems like with this program,
push_front
was worse.Running locally, I get:
and
So it looks like
push_back
is better locally as well, so maybe in general its better to usepush_back
, but I don't really know why this is true after looking at the source code.