We will hold AtCoder Beginner Contest 192.

- Contest URL: https://atcoder.jp/contests/abc192
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20210220T2100&p1=248
- Duration: 100 minutes
- Number of Tasks: 6
- Writer: evima, kyopro_friends, QCFium
- Rated range: ~ 1999

The point values will be 100-200-300-400-500-600.

We are looking forward to your participation!

11 minutes to go All The Best!!

My screencast with commentary will be here once the contest is over.

I'm planning to explain the solutions live on stream after the contest. I'm trying something new and doing it on Youtube — https://youtu.be/XTvl-idpAwc (you can watch the recording here too)

My screencast without commentary is at https://youtu.be/JeiFbb1RKjI (will publish at end of contest).

were most solutions failing in D due to overflow / precision issues ? I thought we can binary search but gave wrong answer in 13 cases even after handling the overflow. submission

UPD : it worked after handling the case where x has length 1 . I handled the case but incorrectly , probably overflow took away all the focus.

I did have to try quite a few times :( but eventually it passed after handling the overflow (using binary search: https://atcoder.jp/contests/abc192/submissions/20332818).

You need to consider case where $$$x$$$ has length 1 as special case.

I hope AtCoder will learn me at one moment

`long long r = 1e18 + 10`

is equal to`1e18`

duo double precision error. This is the third (known) time I made the same mistakeSame situation with me

first i tried to handle the overflow with signed long long but result can have undefined in that case.

Later i fixed that , but for case where $$$x$$$ has length equal to 1, i wrote :

mistakeThere a "few" corner cases as well. Also, yes you have to handle overflow.Submission

For x="1", the value of x is allways 1, independent of base n. So, why is there 0 or 1 solutions (as tutorial states). It should be m-1 possible values for n.

Can somebody explain?

value of $$$x$$$ in that case will be not $$$1$$$ , it will be always $$$x$$$ . for $$$x = 5 , m = 7$$$ answer will be $$$1$$$ , for $$$x = 5 , m = 4$$$ answer will be $$$0$$$.

Thus if $$$x$$$ has length $$$1$$$ , it will remain always $$$x$$$ for any base . Hence if $$$M>=x$$$ answer will be $$$0$$$ else answer will be $$$1$$$.

Ah... I understand. It is not asked for count possible different values of n, but possible different values of x. Thanks.

Take the case x=9 and m=1.

Because we need to find

differentvalues, all of them will be same and equal to x if x has length=1.I think you can only generate one distinct number(1), so the answer is 1,

it's very tricky

You can fix overflow by not thinking of overflow ft. (__int128) My Submission

thanks, changed from long long to __int128 and got AC

why it gives me CE when i use __int128?

run it in c++(gcc 9.2.1)

https://atcoder.jp/contests/abc192/submissions/20416919 why It gives CE. Can you please guide me?

You can print or input an __int128 variable as far as i know. So only use it while comparing.

It seems that E was easier than D.

how to solve E

You can use Dijkstra’s shortest path algorithm.

Is D Binary Search or something else ?

Is D not a simple binsearch? I ended up changing to python to avoid overflow but still did not manage to solve it

Submission: https://atcoder.jp/contests/abc192/submissions/20328749

consider the case when The length of $$$X$$$ is 1, The answer is $$$1$$$ if $$$X <= m$$$ or $$$0$$$ otherwise

Yeahh. I too bricked here and couldn't solve D as I misread the problem and was trying to find the number of possible bases $$$n$$$ instead of the number of distinct values of $$$X$$$ (which turns out to be the same except for the case when the length of $$$X$$$ = 1). Missed yet another chance to AK T_T.

Ahh i see, i misread the problem. Thanks

Why nowadays Atcoder ask a lot of precision error or something similar

Fixed the issue.

I would be really grateful if someone can look into my D submission why it is wrong ? I am doing binary search and dont really seem to have overflow issues My Code

`if (sz(s) == 1) {cout << 1; return;}`

The answer isn't always 1 in this case. For example: X = 9, M = 1

ok, yes, I just realized that I am dumb

Livestream with solutions

Nice Problems!

How could you say that??

It was one of the worst problemset that I have ever seen.

Problem A and B was easy, as always in atcoder.Problem C was tooo easy. Problem D was also really easy, just you should know about precision error. And problem E was just a dijkstra. (And I didn't read problem F)

But D seemed interesting to me!

Not sure what is the interesting part in D. The main source of error here is to miss the edgecase x.length==1. That edgecase was mainly hidden by unclear statement and no such example case.

This is usually considered to be low quality of problem.

If you had participated in last ABC , you will appreciate this round. This contest is for beginners so easy problems does make sense.

.

Can you tell me why are you using Val variable as long double in your AC solution , It is meant to have only integer values I think. One thing more , Why aren't you considering the situation when Val overflows?.

Nice contest.

I think the problems are really good and I enjoy it, what's more, the editorial is available once the contest is over.

If you got wrong answers in D and don't know what's wrong, the bugs might be:

I made the second mistake while solving the problem, so I got a lot of wrong attempt, what a pity! :(

For people facing problems with D, try the following : 1. Handle the case when string's length is 1. 2. During binary search, store the sum in double or long double, and whenever it exceeds M, break the summation loop. Long double is capable of storing large exponents. So it won't cause precision errors.

Thanks...It worked..

I am unable to get my code work around handmade case #2.

On putting certain asserts I also found out the my binary search is not working as expected.

If I am using mid = (l + r) / 2 and then putting asserts, then it is not giving Runtime error on Handmade #1 Link

Can anyone have a look at my submission and tell me what am I doing wrong.

So does it mean , that there won't be overflow for sum in long double? , and one more silly question why was c++ boost created when Long Double can handle cases. sorry if you feel it is way too stupid.

There will not be overflow but loss of precision of number as it gets larger while using long double I believe.

My solutions, along with explanations, can be found here :)

I solved D without binary search. More than that, I did not consider binary search at all!! What I did was separately handle cases where length of $$$X$$$ is $$$1, 2, 3$$$ and bruteforce+stopping early the other cases.

Because the $$$b^3$$$ increases rather fast, $$$b$$$ only need to reach $$$10^6+1$$$ to surpass value $$$M\leq10^{18}$$$, so I don't need to manually handle further on.

I use Python to code, so It feels like I cheated because I don't have to worry about overflow.. Link to submission

would've been much more convenient if the editorial was one-paged instead of having to open different tabs

Can some one tell me why my sol is wrong for D? My solution I don't understand what I missed and it has been so much painful trying to find the mistake. T_T IGNORE I figured it out. It was an obvious dumb mistake :(

Why dijkstra's algorithm works for problem E? i solved it using dijkstra but i don't have a proof why it works.

The idea is that there is no point of arriving later than you can, because you can always wait at the destination, so it's better to find the shortest path. And I believe that with this fact you can just repeat a proof for dijkstra algorithm, maybe with some small fixes.

You can also replace each vertex with infinitely many vertices, one for each moment of time. Then you have some directed edges between vertices, and also directed edges of weight 1 between copies of the same vertex. Then you can just run dijkstra on this graph, and it will work because this is just a directed graph (infinite graph, but whatever). I don't know your exact algorithm, but it should be easy to prove that what you do is more or less equal to running dijkstra on this graph, thus it is correct.

How to solve F ?

Let the sum of elements you will mix be

S.Brute force over the value of

Kfrom1toN(the number of elements you will mix), suppose you want to checkK = 3, then you should take3elements from the array such that the sum of these elements isSand the following conditions holds:S%3 = X%3(because this sum will be increased byKeach second until reachX).Their sum

Sis maximum (because this will decrease the time we need to reachX).The last part (choosing

Kelements such thatS%k = X%Kand their sumSis maximum) can be done using dynamic programming, letdp[i][rem][mod]represents the maximum sum you can get when you are at indexiand has to takeremelements and the sum of elements you taken so far modulusKequalsmod, then you try to take or leave each element and return the optimal answer.Note that the value returned from

dpwill never exceedX, Because the max value you can get is 1e9 andXis at least 1e9.Thanks for the solution. I have one more confusion. Will it be fitted in the specified time limit?

You will iterate over elements from 1 to N, at each iteration you will run dp of time N^3, so the total complixity is O(N^4) and N is at most 100, so it can fit the time limit.

Actually my confusion was exactly there to run a nested loop of four layer which approximately preforming 10^8 operations.

Submission to D. Can someone help me with this submission? It fails only in one test case for problem D.