Problem link: 1661B - Getting Zero submission: 208009051 I tried to solve this problem using the dfs algorithm. But I can't still configure what is causing the MLE verdict. Help if someone can.
№ | Пользователь | Рейтинг |
---|---|---|
1 | tourist | 4009 |
2 | jiangly | 3823 |
3 | Benq | 3738 |
4 | Radewoosh | 3633 |
5 | jqdai0815 | 3620 |
6 | orzdevinwang | 3529 |
7 | ecnerwala | 3446 |
8 | Um_nik | 3396 |
9 | ksun48 | 3390 |
10 | gamegame | 3386 |
Страны | Города | Организации | Всё → |
№ | Пользователь | Вклад |
---|---|---|
1 | cry | 167 |
2 | Um_nik | 163 |
3 | maomao90 | 162 |
3 | atcoder_official | 162 |
5 | adamant | 159 |
6 | -is-this-fft- | 158 |
7 | awoo | 157 |
8 | TheScrasse | 154 |
9 | Dominater069 | 153 |
9 | nor | 153 |
Problem link: 1661B - Getting Zero submission: 208009051 I tried to solve this problem using the dfs algorithm. But I can't still configure what is causing the MLE verdict. Help if someone can.
Название |
---|
I don't see how you dfs must ends, for me it is infinite recursion at first glance
At a particular position, any number will be divisible by 32768(2^15) and have a value equal to zero. As the value is not equal to -1, that will end the recursive call.
You have test input
Why don't we try it?
x = 19
, produces two inner calls (dfs(38)
anddfs(20)
)dfs(38)
produces another two inner calls (dfs(76)
anddfs(39)
)dfs(76)
producesdfs(152)
anddfs(77)
x = 16384
. This will producedfs(0)
anddfs(16385)
dfs(0)
indeed returns 0, butdfs(16385)
? Moving ondfs(16385)
producesdfs(2)
anddfs(16386)
dfs(2)
producesdfs(4)
anddfs(3)
x = 16384
See problem? If not, then your inner dfs calls never terminates.
That's too deep! Thanks. But how can I handle this case?
I don't think that dfs approach works here (at least I don't know any proof for it). I'd do just simple bfs from zero to all values by reversed operations.