Problem link : https://mirror.codeforces.com/contest/1620/problem/C
Submission link : https://mirror.codeforces.com/contest/1620/submission/162394549
| # | User | Rating |
|---|---|---|
| 1 | Benq | 3792 |
| 2 | VivaciousAubergine | 3647 |
| 3 | Kevin114514 | 3611 |
| 4 | jiangly | 3583 |
| 5 | strapple | 3515 |
| 6 | tourist | 3470 |
| 7 | Radewoosh | 3415 |
| 8 | Um_nik | 3376 |
| 9 | maroonrk | 3361 |
| 10 | XVIII | 3345 |
| # | User | Contrib. |
|---|---|---|
| 1 | Qingyu | 162 |
| 2 | adamant | 148 |
| 3 | Um_nik | 146 |
| 4 | Dominater069 | 143 |
| 5 | errorgorn | 141 |
| 6 | cry | 138 |
| 7 | Proof_by_QED | 136 |
| 8 | YuukiS | 135 |
| 9 | chromate00 | 134 |
| 10 | soullless | 133 |
Problem link : https://mirror.codeforces.com/contest/1620/problem/C
Submission link : https://mirror.codeforces.com/contest/1620/submission/162394549
| Name |
|---|



a[i+1] out of bounds.
This won't happen because before that there is an or statement i+1 == n, when this will be true the a[i+1] statement will never run.
Have you noticed $$$x \le 10^{18}$$$?
Your code seems to have a lot of issues, I just fixed it for runtime errors.
Shadowed declaration
string a;andauto mul = [&] (int a, int b).Can be divide by 0
int t = x/prod[i];.What if prod is empty
prod.back() = 1;Can be accessed out of bound
forn(_, take[i])Can be overflow
int ans = A * b;Thanks for replying. This prod[i] cannot be zero. I fixed the prod.back.
forn(_, take[i])canot overflowI have handled overflow using the gfg method. Is not this corrrect?
I am not reviewing your logic, I just pointing out some code that has a potential runtime error.
I see you create vector here with size of vector "cnt"
vi prod(sz(cnt));. If cnt is an empty vector, prod is also an empty vector.In problem constraint, k can be zero, cur always 0 so
cntwill have no elementprodis empty at this point andprod.back()will give an errorIn this code
forn(_, take[i]), I see that you increaseiin the outter loop and try to access the elementtake[i]without checking the size which can be out of bound. A counter-example would bek = 0-> vectortakeis empty ->take[i]will give an error.This is a submission link that I try to fix your runtime error Submission. The overflow still exists, I don't know what method you use to handled overflow but it seems not working
https://godbolt.org/z/7PvxGxKxK
Notice that compiler generate just
imulinstruction.In c++ integer overflow (
int ans = a * b) is UB. And because it is UB, compiler think "whyb == 0 || ans / b == awould not be true?" and just not generate such instructions.Now its MLE:) 162639237