We will hold Monoxer Programming Contest 2022(AtCoder Beginner Contest 249).
- Contest URL: https://atcoder.jp/contests/abc249
- Start Time: http://www.timeanddate.com/worldclock/fixedtime.html?iso=20220423T2100&p1=248
- Duration: 100 minutes
- Number of Tasks: 8
- Writer: Kodaman, PCTprobability, m_99, nok0
- Tester: physics0523, Nyaan
- Rated range: ~ 1999 The point values will be 100-200-300-400-500-500-600-600.
We are looking forward to your participation!
What a contest, I got 10 WAs for this contest: A (2), C (4), F (4)
How to solve E? I tried reducing it to something like
where $$$l = |s|$$$
Let the DP state be:
Think of a transition where you add $$$c'$$$ $$$k$$$ times. In the run-length encoded string, that is equivalent to adding $$$f(k)+1$$$ characters, where $$$f(k)$$$ is the length of $$$k$$$ when written as a number. Since $$$n < 3000$$$, $$$f(k) \leq 4$$$. So, you can transition from $$$dp_{i,l,c}$$$ to $$$dp_{i+k,l+f(k)+1, c'}$$$, for 4 different ranges of $$$k$$$.
Note that the DP transitions will actually be symmetric w.r.t $$$c$$$, i.e. $$$dp_{i,l,c} = dp_{i,l,c'}$$$ for all $$$i,l$$$. With this knowledge, we can just knock that dimension out, making the transition adding $$$25 \cdot dp_{i,l}$$$ to $$$dp_{i+k, l+f(k)+1}$$$. You don't need any complicated structures to add to the ranges of $$$k$$$, you can do this by adding in a prefix-sum-esque way and adding to $$$l$$$ and subtracting from $$$r+1$$$. Hence, you can do the entire DP in $$$O(n^2)$$$.
Though the problems themselves were pretty standard for an ABC, some of them could have been framed a bit better imho.
For example, it took me around 11 mins. to solve A because of the mistake in the problem statement. This could have been prevented if the variable names had been descriptive (speed, duration and rest instead of single alphabets).
And in problem D, clarifications that i, j and k need not be unique and that the division should be exact (not integer division) would have saved 20 mins. for me.
I requested that clarification. It's lucky that as a Chinese I can comprehend at least some Japanese.
At least "meters a second" should be "meters per second".
Someone explain D for English? I tried prime factors approach but didnt correct
Just keep the no. of times a number has appeared in the array. Factor (not prime factor) the number and use some simple combinatorics. It should be done in $$$O(n\sqrt n)$$$.
Thank you. I'll review it
Better way (as in better complexity) is to just use the harmonic series which would give a $$$O(nlogn)$$$ solution.
ah nice, i did not think O(N * sqrt(N)) would pass. the harmonic series approach seems stronger
Actually in D, I am not able to see how ans for sample 3 equals 62?
The indices can be the same. I had the same problem lol
i, j, k need not be unique.
I had to brute force O(n^3) to get 62 and understand the problem
You can do this by enumerating i, and enumerating the multiples of i, and storing them in a
vector
.This should be done in $$$O(n\ln n)$$$Excuse my English is not very good.Because I am a Chinese.
How to solve G and Ex?
Great problems, thanks to the writers. Hope that tutorials could be published as soon as possible.
No Editorial :(
In problem D, I tried two solutions after contest. Both are exactly same, one sorts the input array and the other doesn't. The former got AC (accepted), while the latter got TLE on 5/20 test cases. I'm curious what might've caused this, all the more since according to me, my solution doesn't take advantage of the sorted order of the array in any way.
Problem Link
Accepted solution with sorting
TLE solution without sorting
I know that rather than map, I could've used the vector or array and gotten AC, but in a similar scenario in some other problem, I might think sorting isn't required and fail to solve the problem.
Any help would be much appreciated.
Just guessing: I think the access-patterns on
mp.count(v[i] / j)
are more cache-friendly in the sorted case, at least for low values ofi
. In the unsorted case you have less loop iterations where bothv[i]
andv[i+1]
are low.Hi, Why there's no editorial available yet? chokudai, Kodaman, m_99, PCTprobability, nok0, And also can someone explain the solution of F?
The editorial is out now.
My solution to problem F: Let we add an operation $$$t_0=1,y_0=0$$$. Then, the final value of $$$x$$$ is always consisted of $$$y_i(t_i=1)$$$ and the sum of some(not all) $$$y_j(t_j=2,i<j\le n)$$$. (We will ignore the operations with $$$t_j=1$$$)
In the operations with $$$t_j=2$$$, we can always ignore the smallest negative $$$y_j$$$ to reach the maximum value of $$$x$$$. Thus, the problem becomes maintaining $$$val=\text{the sum of the smallest negative }k'\text{-th } y_j$$$ ($$$k'=k- \text{the number of operations with } t_j=1(i<j\le n)$$$), and this can be done by balance tree, priority queue, segment tree, etc.
My implementation: deal with the operations from $$$n$$$ to $$$0$$$. If $$$t_i=2$$$ and $$$y_i<0$$$, insert it to the treap, then do $$$s\leftarrow s+y_i$$$. If $$$t_i=1$$$, do $$$ans\leftarrow\max(ans,y_i+s-val),k'\leftarrow k'-1$$$.($$$val$$$ is mentioned above)
my code using treap
In Problem E, I can't understand how the optimization is working. Can anyone help me.
The optimization of DP We can find that the g(k) is in [2,3,4,5], so we can use fenwick tree to optimize it. There are n fenwick trees, the i-th is called C[i].
For each i,j: