2256A-Three Numbers on the Blackboard Idea: paulzrm
Sort the numbers as $$$a\le b\le c$$$.
After at least one operation, consider the median.
Doing nothing gives $$$c-a$$$; replacing $$$c$$$ with $$$a+b$$$ gives $$$b$$$.
Suppose the current numbers are $$$x\le y\le z$$$. An operation keeps two numbers and replaces the third with their sum. Since all values are nonnegative, the new sum is no smaller than either retained number. Thus the new median is the larger retained number, which is at least the old median $$$y$$$. The median never decreases.
After an operation that retains $$$u\le v$$$, the numbers are $$$u,v,u+v$$$. Their range is exactly $$$v$$$, also their median. Hence every nonempty sequence of operations ends with a range of at least the initial median $$$b$$$.
With no operation the range is $$$c-a$$$. Replacing $$$c$$$ with $$$a+b$$$ produces $$$a,b,a+b$$$, whose range is $$$b$$$. Therefore the answer is $$$\min(c-a,b)$$$.
The time and space complexities are both $$$O(1)$$$.
2256B-Domino Tiles Idea: paulzrm
Cancel the common term in the inequality between two adjacent dominoes.
The condition is equivalent to $$$s_i\ne s_{i+2}$$$ for every $$$i$$$.
Once the first two characters are fixed, the rest are determined.
Adjacent dominoes have different weights exactly when $$$s_i+s_{i+1}\ne s_{i+1}+s_{i+2}$$$.
Canceling $$$s_{i+1}$$$ gives $$$s_i\ne s_{i+2}$$$. Since the alphabet is binary, this is equivalent to $$$s_{i+2}=1-s_i$$$.
Therefore $$$s_1,s_2$$$ determine the whole string. Enumerate their four assignments and check whether the implied string agrees with every known character. The answer is at most $$$4$$$, so the modulus does not affect it.
The time complexity is $$$O(n)$$$ and the space complexity is $$$O(1)$$$.
2255A-Hot Potatoes at the Fairy Warehouse / 2256C Idea: Error_Yuan
Split the 1s on the cycle into maximal runs. Unless a run covers the whole cycle, initially only its last potato can move.
Passing too early gives the next opportunity to players of the other team.
The last player of each run waits until the final round. Every initial 10 becomes 01, all other potatoes stay still, and the exact value of $$$k$$$ is irrelevant.
The total score is always the number of potatoes, so the game is zero-sum. Consider a maximal run of 1s followed by an empty position. Every potato except the last one is blocked.
If the last potato is passed early, it reaches the other team and leaves an empty position behind, enabling the preceding potato. Both newly enabled players belong to the other team, so with another round the opponent may cancel the point just gained. Passing in the final round leaves no response and is optimal.
Thus only the last potato of each run moves one step in the final round. If the whole cycle is filled, nothing moves. For an initial position $$$i$$$:
- if $$$s_i=1$$$ and $$$s_{i+1}=0$$$, the team owning $$$i$$$ scores;
- if $$$s_i=s_{i+1}=1$$$, the other team scores.
Scan the cycle once. The implementation is zero-indexed: even positions belong to red and odd positions to blue. Their scores are printed in that order.
The time complexity is $$$O(n)$$$ and the space complexity is $$$O(1)$$$.
2255B-A Ribbon for Tomorrow / 2256D Idea: paulzrm
Check whether a valid reversal can change either run count or the first character.
In $$$x^ay^bx^c$$$, choosing one endpoint in each $$$x$$$-run lets us redistribute the total length of those two runs.
Operations redistribute run lengths but do not change the order of run colors.
Split the string into maximal runs. The two endpoints of an operation contain the same character. Internal adjacencies are only reversed, and the endpoint character on either boundary stays unchanged. Hence the numbers of 0-runs and 1-runs are invariant, as are the character counts.
If the reversal contains the first position, the new first character is the old right endpoint, equal to the old first character. Otherwise it is untouched. Thus the first character is invariant. Since run colors alternate, the run counts and first character determine their entire order.
Conversely, consider $$$x^ay^bx^c$$$. A reversal with one endpoint in each $$$x$$$-run can split the total $$$a+c$$$ into any two positive lengths while leaving the middle run unchanged. Repeating this between adjacent runs of the same color realizes any positive composition of all 0s, and independently any positive composition of all 1s. These invariants are therefore sufficient.
If character $$$x$$$ occurs $$$cnt_x$$$ times in $$$seg_x$$$ nonempty runs, its run lengths can be chosen in $$$\binom{cnt_x-1}{seg_x-1}$$$ ways. The two colors are independent, so the answer is $$$\binom{cnt_0-1}{seg_0-1}\binom{cnt_1-1}{seg_1-1}$$$.
An absent character contributes a factor of $$$1$$$.
We can precompute inverses without binary exponentiation. Let the prime modulus be $$$P$$$. Since every required $$$i \lt P$$$, its inverse exists. From $$$P=\left\lfloor\frac Pi\right\rfloor i+(P\bmod i)$$$ we obtain $$$i^{-1}=-\left\lfloor\frac Pi\right\rfloor(P\bmod i)^{-1}\pmod P$$$.
Because $$$P\bmod i \lt i$$$, enumerating $$$i$$$ in increasing order computes each inverse from an earlier one. Factorials and inverse factorials follow in the same loop.
Each test case takes $$$O(n)$$$ time. Preprocessing uses $$$O(N)$$$ time and space, where $$$N=10^6$$$.
2255C-Even If the World Turns / 2256E Idea: paulzrm
Let $$$w$$$ be the number of black cells and $$$S_r,S_c$$$ their coordinate sums modulo $$$n$$$. Observe how they change after a shift.
Since $$$\gcd(w,n)=1$$$, $$$(w^{-1}S_r,w^{-1}S_c)$$$ behaves like the center of mass of the picture.
Swapping a black cell $$$p$$$ with a white cell $$$p+\delta$$$ increases the coordinate sum by $$$\delta$$$.
In the first run, move the center to the target. In the second run, recompute it from the transformed picture.
Identify coordinates $$$1,2,\ldots,n$$$ with $$$0,1,\ldots,n-1$$$ in $$$\mathbb Z_n$$$. Let $$$S=(S_r,S_c)$$$ be the sum of black-cell coordinates. A shift by $$$d$$$ changes it to $$$S+wd$$$. Define $$$C=w^{-1}S$$$. Then $$$C$$$ changes to $$$C+d$$$, exactly as an ordinary cell does.
Every rotation or reflection is an affine map $$$p\mapsto Mp+t$$$. It changes the sum to $$$MS+wt$$$ and therefore changes the center to $$$MC+t$$$, again exactly like a cell.
After color inversion, $$$w'=n^2-w\equiv-w\pmod n$$$. The coordinate sum of the whole board is $$$0$$$ modulo $$$n$$$, so the new black-cell sum is $$$S'=-S$$$. Hence the new center is $$$(-w)^{-1}(-S)=C$$$. Color inversion does not affect it.
In the first run, we want the sum after swapping to be $$$wx$$$. Let $$$\delta=wx-S$$$. If $$$\delta=0$$$, swap one cell with itself. Otherwise find a black cell $$$p$$$ for which $$$p+\delta$$$ is white and swap them.
Such a cell must exist. Otherwise the black-cell set would be invariant under translation by nonzero $$$\delta$$$. Every orbit of this translation has length $$$L \gt 1$$$ with $$$L\mid n$$$. The black cells would be a union of complete orbits, so $$$L\mid w$$$, contradicting $$$\gcd(w,n)=1$$$.
The swap makes the center equal to the target. All later transformations move them together. In the second run, recompute $$$w,S_r,S_c$$$ and output $$$w^{-1}S$$$. Since $$$n\le800$$$, enumerate $$$1\le t \lt n$$$ until $$$wt\equiv1\pmod n$$$; no extended Euclidean algorithm is needed.
Each run takes $$$O(n^2)$$$ time and $$$O(n^2)$$$ space.
2255D-How Long Until Nothing Remains? / 2256F Idea: Error_Yuan
Fix the chosen index in every second and work backward from the final zero array. A current upper bound $$$x$$$ becomes either $$$2x+1$$$ or $$$2x$$$ after one backward step.
If index $$$i$$$ is selected in the seconds in $$$S$$$, it can end at zero after $$$T$$$ seconds exactly when $$$a_i\le\sum_{s\in S}2^{s-1}$$$.
For fixed $$$T$$$, distribute $$$1,2,4,\ldots,2^{T-1}$$$ among the demands. Process them in decreasing order and always choose the largest remaining demand.
Fix all choices during the $$$T$$$ seconds and consider position $$$i$$$. Working backward, if values at most $$$x$$$ can already reach zero, then a preceding selected step allows $$$y$$$ exactly when $$$\lfloor y/2\rfloor\le x$$$, or $$$y\le2x+1$$$. A nonselected step gives $$$\lceil y/2\rceil\le x$$$, or $$$y\le2x$$$. Repeating this proves the condition in Hint 2.
Thus feasibility in $$$T$$$ seconds is equivalent to assigning every capacity $$$1,2,\ldots,2^{T-1}$$$ to one demand so that demand $$$a_i$$$ receives total capacity at least $$$a_i$$$.
Process capacities from largest to smallest. Let the current capacity be $$$p$$$ and the largest remaining demand be $$$x$$$. If $$$x \gt p$$$, all smaller capacities sum to only $$$p-1$$$, so every feasible assignment must give $$$p$$$ to $$$x$$$. If $$$x\le p$$$, let $$$p$$$ finish $$$x$$$. In any feasible assignment giving $$$p$$$ to some $$$y\le x$$$ and a set of smaller capacities to $$$x$$$, swapping those two assignments remains feasible. Hence the greedy rule is correct.
Every positive number must be selected at least once, since repeated ceiling division alone never reaches zero. Thus $$$T\ge n$$$. Also $$$a_i \lt 2^{30}$$$, so $$$T=n+30$$$ is always sufficient. Binary-search $$$T$$$ in this interval.
Every capacity at least $$$2^{30}$$$ can finish one demand alone. Remove the largest $$$T-30$$$ demands with these capacities. At most $$$30$$$ demands remain; put them in a max-heap and simulate only $$$2^{29},\ldots,1$$$.
Sorting takes $$$O(n\log n)$$$. Each check takes $$$O(30\log30)$$$, there are $$$O(\log30)$$$ checks, and the space complexity is $$$O(n)$$$.
2255E1-What Will Remain at the End? (Easy Version) Idea: paulzrm
For each position, its values over all versions form a sequence. Maintain its sum, maximum prefix, maximum suffix, and maximum subarray when appending a segment.
A value is always in $$${-1,0,1}$$$. For each possible initial value, a sequence of operations can store its final value and the summary of the generated history.
This representation is closed under concatenating operation sequences, so it can serve as a lazy segment-tree tag.
Range updates only compose tags. A position's history is materialized when that position is queried by pushing its root-to-leaf tags.
For a nonempty sequence segment, store $$$(S,P,Q,M)$$$: its sum, maximum prefix sum, maximum suffix sum, and maximum nonempty subarray sum. Two adjacent summaries merge in $$$O(1)$$$; a crossing maximum subarray is the left maximum suffix followed by the right maximum prefix.
Fix one array position. Its value lies in $$$V={-1,0,1}$$$. For an operation segment $$$T$$$, let $$$f_T(s)$$$ be the final value from initial state $$$s$$$, and let $$$H_T(s)$$$ summarize the values recorded while executing $$$T$$$. There are only three states, so this representation has constant size.
If $$$A$$$ is followed by $$$B$$$, then $$$f_{AB}(s)=f_B(f_A(s))$$$ and $$$H_{AB}(s)=H_A(s)\mathbin{\Vert}H_B(f_A(s))$$$, where $$$\Vert$$$ concatenates two histories and merges their summaries. Tags therefore compose in $$$O(1)$$$.
Each segment-tree node stores the unpushed operation segment applying to its whole interval. A range update composes tags in $$$O(\log n)$$$ nodes. After each operation, a record-current-value event is applied to the whole tree to create the new version.
A query at $$$p$$$ pushes the tags on its root-to-leaf path and materializes all history since the previous query. If the old history has maximum suffix $$$Q_0$$$ and maximum subarray $$$M_0$$$, while the new segment has $$$(S,P,Q,M)$$$, then $$$M'=\max(M_0,M,Q_0+P)$$$ and $$$Q'=\max(Q,Q_0+S)$$$.
Only these two old values need to persist at each position.
Record version $$$0$$$ initially. A type-4 operation at time $$$i$$$ queries versions $$$0$$$ through $$$i-1$$$, so answer it before recording version $$$i$$$, which equals version $$$i-1$$$. Other operations update first and record afterward. Decode online input modulo $$$2^{64}$$$ exactly as specified.
The total time complexity is $$$O((n+q)\log n)$$$ and the space complexity is $$$O(n)$$$.
2255E2-What Will Remain at the End? (Hard Version) Idea: paulzrm
The segment tree and historical maximum-subarray framework are unchanged from G1. Only the constant-size operation tag changes.
Before the first assignment, after fixing the sign of the initial $$$x$$$, every value is one of $$$-|x|,0,|x|$$$.
The first assignment removes all dependence on $$$x$$$. Split a tag into a coefficient prefix depending on $$$|x|$$$ and a fixed numeric suffix.
To compose $$$A$$$ followed by $$$B$$$, distinguish whether an assignment has occurred in either segment.
Solution 1
Without assignments, negation changes only the sign and $$$\max(x,0)$$$ only replaces a negative value with zero. For each of the three initial signs, store the summary of the coefficient sequence and the final coefficient in $$${-1,0,1}$$$. Substituting the real input multiplies the sequence by $$$|x|$$$.
The first assignment is a dividing point. Before it, values still depend on $$$x$$$; from it onward, they are fixed. Represent an operation segment by:
- a coefficient prefix depending on $$$|x|$$$, stored for all three initial signs;
- a fixed numeric suffix and the final actual value.
This representation has constant size. It is also closed under concatenation.
If $$$A$$$ contains an assignment, its output is constant. Feeding that constant into $$$B$$$ fixes all history produced by $$$B$$$, so concatenate the fixed histories.
If neither segment contains an assignment, compose their three coefficient states exactly as in G1.
If only $$$B$$$ contains an assignment, append the part of $$$B$$$ before its first assignment to each coefficient prefix of $$$A$$$. The fixed suffix of $$$B$$$ becomes the fixed suffix of the result. Every case takes $$$O(1)$$$.
Assignment, negation, $$$\max(x,0)$$$, and recording a version all have direct tags of this form. The remaining segment-tree logic and version ordering are identical to G1.
The total time complexity is $$$O((n+q)\log n)$$$ and the space complexity is $$$O(n)$$$.
Solution 2
There is also an amortized solution that performs operation $$$3$$$ directly on the segment tree. Store the current minimum $$$mn$$$ and maximum $$$mx$$$ in every node. Range assignment and range negation use ordinary lazy tags. For operation $$$3$$$:
- if $$$mn\ge0$$$, do nothing;
- if $$$mx\le0$$$, assign zero to the whole node;
- otherwise the node contains both positive and negative values, so recurse into its children.
Thus operation $$$3$$$ never has to appear in a historical tag. It is materialized as several range assignments to zero.
Call a segment-tree node bad if $$$mn \lt 0 \lt mx$$$.
Let the potential $$$\Phi$$$ be the number of bad nodes. When a fully covered node is negated, $$$(mn,mx)$$$ becomes $$$(-mx,-mn)$$$, so the bad status of that node and every node below it is preserved. Assignment can only remove bad nodes. A range assignment or negation recomputes nodes only on its two boundary paths, so it creates at most $$$O(\log n)$$$ new bad nodes.
Now consider operation $$$3$$$. Apart from $$$O(\log n)$$$ nodes on the two boundary paths, every internal node into which the recursion continues was bad before the operation. After the operation, its interval contains no negative value, so that bad node has disappeared. A recursion tree has at most one more terminal node than internal nodes. Hence one operation costs $$$O(\log n+D)$$$, where $$$D$$$ is the number of bad nodes destroyed by this operation. Operation $$$3$$$ creates no bad nodes. The initial potential is $$$O(n)$$$, while all other operations increase it by only $$$O(q\log n)$$$ in total. Therefore all operation-3 recursions take $$$O(n+q\log n)$$$ time altogether.
The historical part still uses the four-value sequence summary from G1. After every operation, append one record-current-value event at the root. Since every clamp has already been materialized as assignment to zero, pending historical actions contain only assignment, negation, and recording.
Before the first assignment, an initial value $$$x$$$ can only become $$$x$$$ or $$$-x$$$. It is therefore enough to keep two initial states, negative and nonnegative, storing the generated coefficient-sequence summary and the final sign. After the first assignment, all later values are independent of the initial input, so keep a fixed numeric suffix and the final value. Two such tags still compose in $$$O(1)$$$ in chronological order.
For a query at $$$p$$$, push all tags on the root-to-leaf path and append the new history summary to the already materialized history of that position. Version $$$0$$$ and type-4 recording are handled in the same order as in Solution 1.
The total time complexity is $$$O(n+q\log n)$$$ and the space complexity is $$$O(n)$$$.
2255F-Who Will Witness the End? Idea: paulzrm
View each factor $$$a_u+a_v$$$ as choosing one endpoint of edge $$$(u,v)$$$. Every exponent is $$$0$$$, $$$1$$$, or $$$2$$$. The numbers of vertices with exponents $$$0$$$ and $$$2$$$ are equal, and these two types alternate after all other vertices are removed.
The coefficient of a monomial type depends only on the number of variables appearing twice. Express the answer using $$$e_re_{n-r}$$$, where $$$e_r$$$ is the $$$r$$$-th elementary symmetric polynomial.
Coefficient comparison gives a linear system that can be eliminated from high indices to low indices. Direct elimination is $$$O(n^2)$$$; use the ratio of adjacent $$$c_k$$$ and Pascal's identity to derive a short recurrence.
Adjacent equations give a second-order recurrence in $$$h_r,h_{r+1},h_{r+2}$$$. All $$$e_r$$$ are coefficients of $$$\prod_{i=1}^n(1+a_ix)$$$ and can be computed by divide-and-conquer NTT.
Expand the weight of one cyclic ordering. Choosing one term from $$$a_u+a_v$$$ is equivalent to orienting edge $$$(u,v)$$$ toward the chosen endpoint.
Every vertex has degree two, so its exponent is $$$0$$$, $$$1$$$, or $$$2$$$. The exponent sum is $$$n$$$, hence the numbers of vertices with exponents $$$0$$$ and $$$2$$$ are equal; call both numbers $$$k$$$.
Fix these two sets. An exponent-0 vertex has both edges directed outward, an exponent-2 vertex has both directed inward, and every ordinary vertex has one edge in and one out. After ordinary vertices are removed, the two special types must alternate. Conversely, alternation uniquely determines the orientations of all paths between them.
For $$$k\ge1$$$, the $$$2k$$$ special vertices have $$$(2k-1)!$$$ relative cyclic orders. Fix one exponent-0 vertex as the start. The exponent-2 vertices can be permuted arbitrarily, as can the remaining exponent-0 vertices, giving $$$k!(k-1)!$$$ alternating orders. Inserting the other $$$n-2k$$$ vertices does not change this ratio. Therefore the coefficient of this monomial type over all cyclic orders is
For $$$k=0$$$, every vertex has one edge in and one out. The whole cycle must be consistently clockwise or counterclockwise, so
Now consider a symmetric-polynomial representation. Let $$$e_r$$$ be defined by
In $$$e_re_{n-r}$$$, fix a monomial with $$$k$$$ variables appearing twice and $$$k$$$ absent. Repeated variables must be chosen from both factors and absent variables from neither. Choose $$$r-k$$$ of the remaining $$$n-2k$$$ variables for the first factor, so its coefficient is
Let $$$m=\lfloor n/2\rfloor$$$ and write the answer as
Comparing each monomial type gives
Equation $$$k$$$ contains only $$$h_k,h_{k+1},\ldots,h_m$$$, with coefficient $$$1$$$ on $$$h_k$$$. Thus the variables can be solved from large indices to small indices, but doing so directly takes $$$O(n^2)$$$.
For $$$k\ge1$$$, divide two adjacent coefficients:
The $$$k=0$$$ case follows directly from $$$c_0,c_1$$$. Hence
Define
Fix $$$k$$$, set $$$N=n-2k$$$ and $$$j=r-k$$$, and let $$$A_t=\binom{N-2}{t}$$$, with out-of-range binomial coefficients equal to zero.
Using Pascal's identity twice,
Now use
together with $$$r=k+j$$$ and $$$n=N+2k$$$. The entire coefficient calculation can be displayed as
Substituting into $$$L_k$$$ and shifting the latter two indices gives
where out-of-range $$$h$$$ values are zero. Define
Then
Equation $$$k$$$ contains only $$$E_k,E_{k+1},\ldots,E_m$$$, with coefficient $$$1$$$ on $$$E_k$$$. Apart from the top boundary, backward elimination gives $$$E_r=0$$$, or
The highest two terms come directly from the original system:
If $$$n=2m+1$$$ is odd, these values satisfy $$$E_{m-1}=-E_m$$$. Their binomial coefficients in every sum are equal, so they cancel. The remaining equations give $$$E_{m-2},E_{m-3},\ldots,E_0=0$$$. Apply the second-order recurrence starting from $$$m-2$$$.
If $$$n=2m$$$ is even, the first two values give $$$E_{m-1}=0$$$, but $$$E_m$$$ has no matching boundary term. Compute one more value from the original system:
It satisfies $$$E_{m-2}=-E_m$$$. Again their coefficients are equal and they cancel, giving $$$E_{m-3},E_{m-4},\ldots,E_0=0$$$. Apply the recurrence starting from $$$m-3$$$.
Finally compute all $$$e_r$$$ by multiplying the $$$n$$$ linear polynomials $$$1+a_ix$$$ with divide and conquer, using NTT for every convolution. Substitute the resulting coefficients into $$$\sum_{r=0}^m h_re_re_{n-r}$$$.
The time complexity is $$$O(n\log^2 n)$$$ and the space complexity is $$$O(n\log n)$$$.








Auto comment: topic has been updated by paulzrm (previous revision, new revision, compare).
Lightning Fast Editorial, Thank you!!
Great contest imo, at least the problems themselves :)
D1C was amazing
Great contest, I thought i did something wrong when i got that the answer for 2256B was <=4, lol
really fun contest to do! going to watch sukasuka because of this!
I personally switched from C to D when I observed two things that i found hard to combine: 1. there is a case when we have one black tile — i assume, it should be moved to the secret location 2. there is a case where all tiles but one are black — i assumed we should swap empty one with the target.
I think editorial accomplishes 1. but for 2. it does something else, right? Does it cut the "opposite" tile, whatever this means?
I gave 1C and 1D the same score so that everyone could freely choose which problem to solve. I wonder how many contestants noticed this :-)
Excuse me, did you get the idea of 1C from learning the representation theory of finite group?
During the round I found it helpful for me to think of the special case where you put one black tile wherever you want, and then generalize that to $$$w$$$ black tiles. Then I kinda just went toward center of mass because it seemed like it would hold under the transformations and you can prove it does.
I personally avoided the issue by saying that the "correct" version is the one with black cells $$$\le 50\%$$$ of the grid, and flipping them all if this condition is violated. Intended solution is even simpler, flipping doesn't change the center of mass at all.
At least I tried to solve a task with Chtholly using chtholly tree 386390995
Do you know how to improve operations 2 and 3 while keeping the chtholly tree idea?
Sorry, but before the contest, I deliberately generated test cases to break the Chtholly Tree, since this data structure only works when the input is guaranteed to be random XD
BinaryForces
What you may not know is that the original Div. 2 A also took a binary string as input, but we eventually replaced it with another problem lol
great contest, thank you!
While totally overkill, Div2B can also be solved with DP.
$$$dp[i][ld]$$$ where $$$i$$$ is the position and $$$ld \in [1,4]$$$ is the value of the last two digits at $$$i$$$ in binary. Transitions are just the ones where the sum between $$$s_{i-1}$$$ and $$$s_{i}$$$ is different from the sum between $$$s_{i-1}$$$ and $$$s_{i-2}$$$. For example, if I set the current digit to $$$0$$$, only transitions from $$$dp[i-1][ld]$$$ with $$$ld = 2 = 10_2$$$ and $$$ld = 3 = 11_2$$$ are possible.
386346044
Yes. This was the way I solved the problem. The DP iteration formula also shows that the final answer is between 0 and 4 inclusively.
Can someone explain more about this modular center of mass. I can see that its not exactly same as the physical centre of mass. Coz shifting in a normal sense would move the Centre by the same delta, but if the shift is cyclic, it won't (physically).
Example : consider a 7 by 7 square, with first and last column fully black. Now the centre is at (3,3), now consider shifting it by +1 to the right, the physical centre moved by -2.5, but the modular one, accoring to the editorial, moves by +1. And now consider inverting colors also, pyhsically from (3,0.5) it should move to (3,5.5), but modularly acc to the edi, it doesnt change.
Also are there some other problems or anything relateed to this? ppl didn't just come up with this out of nothing i assume.?
But yeah, many many submission seem AI, all have same variable names, cx rx sc sr tc tr,
anyways, div2 D was cool.
Shifts: You increased all the x coordinates (or y coordinates) by 1, so the center of mass shifts by 1 (with mod if needed). The actual center cell moves the same way.
Rotations and reflections: Consider mapping $$$x$$$ to $$$n+1-x$$$. Then if the previous sum is $$$\Sigma x$$$, then the new sum would be $$$wn + w - \Sigma x$$$, which if you divide by $$$w$$$ becomes $$$n + 1 - \overline{x}$$$, which is exactly where the center cell moves as well.
Inverting the colors: I bypassed this issue by saying that the "correct" picture is the one with less than half black cells. If there were more than half black cells then I would just flip it back.
i think i still didn't get my answers
If you are looking for a graphical/physical sense of what the modular center of mass means, I don't think there is such intuition as there is for the non-modular center of mass. Consider that perturbing w or n slightly will completely change the center.
In div.1 D you don't need to do binary search. In fact, if we denote $$$n+\max(\lceil\log a_i\rceil-i)$$$ (with $$$a_i$$$ sorted) as $$$h$$$, then $$$T=h+1$$$ is always sufficient, while $$$T=h-1$$$ is never sufficient. So, you only need to check if $$$T=h$$$ works.
Thanks for the fast rating update!
I have an alternative derivation of the condition in the 2nd hint of D1D 2255D - How Long Until Nothing Remains?
we can rewrite $$$ \left\lceil\dfrac{a_i}{2}\right\rceil $$$ as $$$ \left\lfloor\dfrac{a_i + 1}{2}\right\rfloor $$$
let's look at what happens on a single element $$$ a_i $$$ if it isn't chosen
after one step its value is $$$ \left\lfloor\dfrac{a_i + 1}{2}\right\rfloor $$$
after two steps, its value is $$$ \left\lfloor\dfrac{ \left\lfloor\dfrac{a_i + 1}{2}\right\rfloor +1}{2}\right\rfloor = \left\lfloor\dfrac{a_i + 1 + 2}{4}\right\rfloor $$$
if we continue this for k steps: $$$ \left\lfloor\dfrac{a_i + 1 + 2 + 4 + \dots + 2^{k-1}}{2^k}\right\rfloor = \left\lfloor\dfrac{a_i + 2^k - 1}{2^k}\right\rfloor $$$
what if the element was chosen at some specific second $$$ s $$$? choosing the element means applying $$$ \left\lfloor\dfrac{a_i}{2}\right\rfloor $$$ instead of $$$ \left\lfloor\dfrac{a_i + 1}{2}\right\rfloor $$$ i.e. we do not add 1 at second $$$ s $$$
thus, if index $$$ i $$$ is selected in the seconds in the set $$$ S $$$ it's final value after $$$ T $$$ seconds will be:
$$$
for this value to be equal to $$$0$$$ we need:
a_i + 2^T - 1 - \sum_{s \in S} {2^{s-1}} \lt 2^T \Rightarrow \\ a_i \leq \sum_{s \in S} {2^{s-1}}
$$$
Wow, this is a very straightforward derivation, thank you!
Is no one going to acknowledge the fact that the editorial doesn't mention anything regarding the joke of printing answer mod 998244353 in 2256B.
DIC is the most interesting problem i have ever seen concerning Congruence Algebra:)
Hurray! I got to reach expert in this contest. I target 4 div2 problems in each contest, and today i managed to solve them all.
But it somewhat feels like good luck, that i am able to solve them. Sometimes it happens that I am stuck on problem 3 and am completely blank.
Is it just me, or it happens to all of you guys too.
Moving from expert to CM feels completely impossible.
Please share advice and your experience — Senior Coders :)
386398944 can any one tell me why y randomization get tle The time complexity is o(22*30*n) == 2e8 which suppose pass in 2 sec
386398944 can any one tell me why my randomization get tle The time complexity is o(22*30*n) == 2e8 which suppose pass in 2 sec
In Div2 i think C was easier than B
I can't solve C but I solve B I think C is harder
D1C/D2E is interesting!
I think D1A&B&C/D2C&D&E are all great problems with intersting ideas :D
Is the sample output of div2 E incorrect? The answer for the first test case in the second run should be 2 5 instead of 1 1.
You should note that the samples do not necessarily follow my strategy; they only need to be logically valid.
Oh I got it. Thank u! :D
good cotest btw
Someone, please tell me how do i even approach problems like D, how do i even start, i was braining on DP solution to the problem , I want to solve D,because generally(6/10 times) it's not constructive while C is constructive almost every time.
Yes, I thought DP until I saw that the operations can be applied onto each other. It's kind of like you make a prediction on how the problem will behave (like you guess that you can achieve every possible len > 1 of 0 blocks and 1 blocks using the given operation) and then you proof by AC??? Somebody who solved it pls explain how you arrived at the solution.
well, the first idea is to transform the string into the array of numbers representing the lengths of the consecutive blocks $$$a$$$. then the thing i noticed is that an operation simply subtracts some $$$x$$$ from block $$$a_i$$$ ($$$x \lt a_i$$$ as there should be left at least one symbol) and adds that $$$x$$$ to another block $$$a_j$$$ (and $$$i \equiv j \pmod 2$$$ as the blocks must be the same color). therefore the number of blocks and the order(parity) cannot change, and our task is to count the number of distinct arrays $$$a$$$, which reminds me of the basic combinatorics problem stars and bars
Not really the best contest ever because the first 3 problems were like 800 — 1000 — 1000 and then immediately D was 1900 so RRRRIIIIIPPPPPP.
Upsolved Div1D and got AC with seemingly exponential set-packing solution but with pruning of possible masks 386546135 (if for all bit-prefixes, popcount of mask A is <= popcount of mask B, then we can prune B). I'm curious if this is just weak tests or there is some underlying reason the outstanding mask set can't grow too big.
EDIT: hacked
I like that the solutions to these problems are rigorous like actually showing that the invariants are enough to cover all cases rather than proving only that the invariants work. I think more editorials should do this.
C-physics>>?
My intution for Div2 D is count total no. of palindromes and subtract it from total no. of subarrays whose s[l] = s[r]. Can somebody explain why this giving wrong answer.
386738843
!?Data Structure!?
Can someone explain D1B please ty <3
peak cinema
D2D/D1B. A Ribbon for Tomorrow
Operation: pick
l ≤ rwiths[l] == s[r], reverses[l..r].1. The block structure is invariant
Write
sas maximal blocks:(1,o₁)(0,z₁)(1,o₂)(0,z₂)…Reversing a subarray with equal endpoints never changes how many blocks of each character exist:
So the number of 1-blocks (
k₁) and 0-blocks (k₀) is fixed forever, as are the totalscnt₁,cnt₀.Example:
1100010 → 1000110 / 1101000 / 1100100— always 2 blocks of 1 and 2 blocks of 0.2. Sizes can be redistributed freely
Look at a piece
(1,o₁)(0,z₁)(1,o₂), lets = o₁+o₂. Choosing the two 1-endpoints and reversing, we can reach every(1,1)(0,z₁)(1,s-1), (1,2)(0,z₁)(1,s-2), …, (1,s-1)(0,z₁)(1,1)i.e. we can move 1s between adjacent 1-blocks while the 0-block between them is untouched. Symmetrically for 0s.
Example:
111001 → 110011 / 100111— the 1s redistribute as3+1 / 2+2 / 1+3, while the 0-block stays size 2.Applying this to every adjacent pair, without loss of generality:
So the sizes of the 1-blocks and the sizes of the 0-blocks are independent, and the only constraint is that every block is non-empty. Any such configuration is reachable, and reachable configurations are exactly these.
Counting : The answer is the number of ways to write
cnt₁as an ordered sum ofk₁positive integers, times the same for zeros — classic stars and bars:Hi, can anyone please explain me the solution of the 2255F- Who will witness the end?
In D1C / D2E, I noticed that I must flush the output buffer after every test case, otherwise I'll get "Idleness limit exceeded" on the later testcases? Usually if this is the case for technical reasons, there'll be a paragraph in the problem statement pointing this out.