Блог пользователя Noob-ita-coder

Автор Noob-ita-coder, история, 6 лет назад, По-английски

Can someone help me in finding why my code TLE's for some cases.

Code: https://gist.github.com/medhruv7/98e802016a9f9c34cbe3e7dc178c0dd4

Problem: https://cses.fi/problemset/task/1195/

  • Проголосовать: нравится
  • +6
  • Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

I would suggest dijkstra.

To take care for the coupon we need to maintain two best values per city, one without having used the coupon, one with having used it.

We would use a priority_queue else TLE since it is to much state changes. It took me some tries to find a configuration where it is AC. Not sure if this is hackable.

I assume it would work if you use a priority_queue in function dick().

Code
»
6 лет назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

»
6 лет назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

I've solved the same problem recently with coincidentally the same idea as your's, here's my AC submission. https://paste.ubuntu.com/p/cKqC9Gfv6S/