Блог пользователя feecIe6418

Автор feecIe6418, история, 21 месяц назад, По-английски

Thanks for participation!

Update: added alternative solutions/proofs for A,B,D,F

1988A - Split the Multiset

Hint 1
Solution
Code (python)

1988B - Make Majority

Hint 1
Hint 2
Solution
Another Solution
Code (python)

1988C - Increasing Sequence with Fixed OR

Hint 1
Hint 2
Solution
Code (python)

1988D - The Omnipotent Monster Killer

Hint 1
Hint 2
Solution
Another Solution
Code (C++)

1988E - Range Minimum Sum

Hint 1
Hint 2
Solution
Code (C++)

1988F - Heartbeat

Solution
Code (C++, FFT)
Code (C++, Interpolation)
Разбор задач Codeforces Round 958 (Div. 2)
  • Проголосовать: нравится
  • +147
  • Проголосовать: не нравится

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +12 Проголосовать: не нравится

thanks for super fast editorial

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

Super Fast!!

»
21 месяц назад, скрыть # |
Rev. 3  
Проголосовать: нравится +104 Проголосовать: не нравится

there is also an O(n) solution for D.

we call the number of turn that a monster gets killed its colour.

we know that someone's colour is at most its degree +1.

if just maintain the two minimum colouring's and its colours for a subtree we can update our answer as follow:

we can fix the root colour from 1 to degre+1 and in each colourthe colouring for its children is the minimum colouring except the ones that its colour are same as the root. so their colouring is the second minimum one.

so we can solve it with a dp in O(n) time.

my code: 270694011

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

omg fast editorial :-)

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I felt A >>> B in terms of difficulty

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +90 Проголосовать: не нравится

Possible proof for A: Think of number n as n '1's in a chain, connected with n-1 bonds. Each step could break a maximum of k-1 bonds. Hence the answer.

»
21 месяц назад, скрыть # |
Rev. 3  
Проголосовать: нравится +44 Проголосовать: не нравится

For D: The Omnipotent Monster Killer I created a video editorial

I also created a practice contest for you to submit and verify your cubic and quadratic solutions. https://mirror.codeforces.com/group/7Dn3ObOpau/contest/536755

For E: Range Minimum Sum also I created a video editorial and a practice contest which you can find here

Before attempting E: Range Minimum Sum, try these standard and easy version of the problem.

Standard

Easy Variations

Difficult Variations

In the past, I have also created a video on this topic.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +24 Проголосовать: не нравится

Alternate for D : Note that a monster $$$v$$$ will die within $$$\leq deg[v]+1$$$ rounds. The problem could be formulated as follows , assign $$$t[v]$$$ (round number in which the monster gets killed) to each vertex $$$v$$$. Then you have to minimize the sum of $$$a[v].t[v]$$$ . For each vertex $$$v$$$ , we can keep a $$$deg[v] + 1$$$ sized vector , where each corresponds to the round number at which it was killed. Now using dfs and suffix / prefix minima , we can evaluate this value is $$$O(N).$$$

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +7 Проголосовать: не нравится

Can somebody explain what is being done in D. Or at least direct me to relevant resources.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can someone point out my mistake in c i did the same thing as editorial submission of c

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Whats the counterexample for solving D by making the tree into a bipartite graph, then removing the side of the graph with the greater attack amount?

  • »
    »
    21 месяц назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +3 Проголосовать: не нравится

    you can consider the line graph 1-2-3-4, with attack values 100, 1, 1, 100.

    • »
      »
      »
      21 месяц назад, скрыть # ^ |
       
      Проголосовать: нравится 0 Проголосовать: не нравится

      Why wouldn't that method work? Isn't it optimal to first get attacked by all monsters (hence a loss of $$$202$$$ health points) and then attack two non-adjacent monsters, to then be attacked by the two remaining ones before they, too, get killed? With a minimum decrement of $$$303$$$ ($$$100+1+1+100+(100+1)$$$)?

      In other words, the following: - First round, all monsters attack. $$$202$$$ health points are lost. Two non-adjacent monsters of $$$101$$$ and $$$1$$$ attack points get killed. - Second round, all remaining monsters attack. $$$101$$$ health points are lost. The rest gets killed.

      I believe I am missing something obvious here, but I don't see it.

  • »
    »
    21 месяц назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    4
    100 1 1 100
    1 2
    2 3
    3 4

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

best contest, but in my opinion E is easier than D

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

Can someone give me an example for problem D where $$$b_i$$$ is greater than $$$3$$$ for any node?

  • »
    »
    21 месяц назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I'd like to see an example too. Here is my perhaps wrong proof:

    In the first round, you can reduce the whole tree to pairs of two or lone nodes. Because, imagine a line of 3 nodes: just remove the node in the middle and it becomes two lone nodes.

    Then, in the second round, remove all the lone nodes and 1 node from each pair of 2.

    Then, in the third round, remove all the lone nodes.

  • »
    »
    21 месяц назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +77 Проголосовать: не нравится

     The optimal solution should be red -> green -> blue -> black. This can be generalized to any graph with $$$2^n$$$ vertices needing at least $$$n+1$$$ rounds, by adding another monster of sufficiently large attack power connected to each vertex in the configuration for $$$n-1$$$.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +5 Проголосовать: не нравится

Is it true that the total rounds in D is $$$ \le 3$$$?

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится +27 Проголосовать: не нравится

I have a different solution for B. Compress adjacent 0s into just one 0 (ex. 0010001 -> 0101). Note that replacing every substring with majority 0 is of the form 0 + 10 * k such that k is an integer, so removing these strings doesn't change the number of 0s and 1s. Thus, just check if there are more 1s in this compressed string than 0s. Here is my submission link. I'm surprised that the intended solution is casework.

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится +51 Проголосовать: не нравится

A case for Bonus: Find a counterexample for $$$b_i≤18$$$ when $$$n=300000$$$.

Explanation: we delete all leaf nodes at a time. Then the tree becomes the largest subtree of the previous tree.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Problem B :(Make Majority) Video Editorial YOUTUBE VIDEO LINK (Make Majority) --Click Here

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +17 Проголосовать: не нравится

Another solution to B

First, all continuous $$$0$$$ can be transformed into one $$$0$$$ using one operation. Then we can consider the simpler form.

It's obvious that the pattern like $$$101$$$ can be reduced into $$$1$$$, so all $$$0$$$ except the first and the last character. so we can just compare the number of $$$1$$$'s and the number of longest continous $$$0$$$ segment.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +11 Проголосовать: не нравится

There's an $$$O(n\log n)$$$ solution to E without using the cartesian tree by calculating the contribution of each $$$a_i$$$

https://mirror.codeforces.com/contest/1988/submission/270728340

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится -9 Проголосовать: не нравится
»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +14 Проголосовать: не нравится

There is another solution for problem E. The point is to look at the contribution of each element in the permutation to the answers.

For each element we calculate the first and second element smalller than them to the left and to the right. This can be done in $$$O(n\cdot logn)$$$ using binary search and sparse table.

Then for each element we want to analyse the contribution of subarrays for which the current element is the minimum. We look at the segment of elements until the first smaller one to the right, let's say it has size $$$A$$$ (not including the element itself) and let's call the right one $$$B$$$. To everyone that is in the left segment, the number of subarrays for which the current element is the minimum is $$$A \cdot (B + 1)$$$ and for everyone in the right segment its $$$(A + 1) \cdot B$$$. For the first eleement smaller than the current element to the left, the number of subarrays is $$$(B + 1)\cdot ($$$ size of segment to the left including all elements up until the second element smaller than him $$$)$$$ . Same logic can be used to calcuate contribution of current element to the first ellement smaller to the right. For everyone else, that is everyone left of the first smaller element to the left and everyone right of the first smaller element to the right, the contribution is $$$(A + 1) \cdot (B + 1)$$$. Some edge-cases need to be handled for when there is no element smaller to the left or to the right however this is the gist. The contribution can be added up with lazy segment tree or even with prefix sums.

For details of implementation you can look at my code. code

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In editorial of pD, "taking max part" should be "taking min part"

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +21 Проголосовать: не нравится

Did poor in this round, but really nice problems! The other side of getting bad result is finding unseen shortages for improvement :)

»
21 месяц назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

nvm

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I think for A, a simple proof (or rather intuition) can be : Let's say you do not divide the element into (k-1) 1's and (n-k+1), and lets say you divide it into some number (possibly zero) number of 1's and a bunch of other numbers. Let the minimum number be p, then, to make p into 1 again (which is our goal), you'll need another operation in the future to convert it. Thus, you are needing more than 1 operation to convert a number into 1. Greedily, we should ideally use only 1 operation to convert a number (or part of it) into 1's. Thus, the ideal strategy becomes to convert the numbers into (k-1) 1's and (n-k+1)

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

The suggested method for B feels unnecessarily complex and invites mistakes by having multiple cases. Instead, another approach is to collapse each continous sequences of 0 into a singular 0, then compare if there's more 1s than 0s.

My (python) code: https://mirror.codeforces.com/contest/1988/submission/270651964

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

B was a really easy question

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In D, I used recursive DP[n][20] but still TLE in test case 20. Can somebody explain why?

Solution: https://mirror.codeforces.com/contest/1988/submission/270724498

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +19 Проголосовать: не нравится

Another proof for # turns for pD: notice vertices not chosen in a round should connect to at least one chosen vertex, otherwise we can also choose it, then consider CC form by non-chosen vertices, every vertex in same CC would have different adjacent chosen vertices, then if there exist a (non-chosen)CC with size > n / 2, there also have > n / 2 chosen vertices, which means total nodes > n, which leads to a contradiction, so max size of CC form by non-chosen node would halve.

Then to construct the case where $$$O(\lg n)$$$ turns is needed, we can use the idea of above proof:

start with single node with weight $$$2^1$$$, call such tree $$$T_1$$$, then define $$$T_i$$$ ($$$i \gt 1$$$) as the tree by first use a node with weight $$$2^i$$$ to connect two $$$T_{i - 1}$$$, then for each node haven't connect to a node with weight $$$2^i$$$, create a node with weight $$$2^i$$$ and connect to it, then $$$T_i$$$ would have about $$$2^i$$$ nodes and require $$$i$$$ turns to eliminate.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +25 Проголосовать: не нравится

Hi, how to compute $$$f(n,i,j)$$$ in $$$O(n^3)$$$ in F editorial? I was only able to come up with $$$O(n^4)$$$ or $$$O(n^3 log(n) )$$$ solutions for this subproblem.

  • »
    »
    21 месяц назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    .

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится +20 Проголосовать: не нравится

    Disclaimer: I haven't implemented it myself yet, but that seems to be the logic behind jiangly's solution (270732930)

    Let's build permutations of length $$$n + 1$$$ by inserting a $$$1$$$ into a permutation of length $$$n$$$ of numbers $$$2, 3, \dots, n + 1$$$, so we have $$$n + 1$$$ positions to insert to. These positions can have one of the $$$4$$$ types:

    1. First position. In this case both the number of ascents and the number of prefix maximums increases by one.

    2. Ascent positions, i.e. we insert a $$$1$$$ between elements $$$p_i$$$ and $$$p_{i+1}$$$, such that $$$p_i \lt p_{i+1}$$$. In this case both the number of ascents and the number of prefix maximums do not change.

    3. Nonascent positions, i.e. we insert a $$$1$$$ between $$$p_i$$$ and $$$p_{i+1}$$$, but $$$p_i \gt p_{i+1}$$$. In this case the number of ascents increases by one, but the number of prefix maximums stays the same.

    4. Last position. Nothing changes.

    Now we can count the number of positions of each of those types to get the transitions from $$$f(n, i, j)$$$:

    1. Only one, so $$$f(n + 1, i + 1, j + 1)~+= f(n, i, j)$$$.
    2. Exactly $$$j$$$, so $$$f(n + 1, i, j)~+= j \cdot f(n, i, j)$$$.
    3. There are $$$n - 1$$$ positions between two consecutive elements and $$$j$$$ of them are ascent, so $$$n - 1 - j$$$ are remaining: $$$f(n + 1, i, j + 1)~+= (n - 1 - j) \cdot f(n, i, j)$$$.
    4. Only one, so $$$f(n + 1, i, j)~+= f(n, i, j)$$$.
»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

In problem D, Why does the maximum B of a node is deg(x) + 1? I cannot find any comment to prove it.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

First, thank for very good contest and fast editorial I am going to share my O(n) solution for D We can notice that in optimal solution, monster in node v can be kill in at mode |v| round (|v| is number of node have the same edge with D, round number from 0) So we can call dp[v][round]: minimum number of health decreases when kill monster in node v after "round" dp[v][round]= ∑_(u ∈chill of v) (min)⁡(dp[u][j]) (j ≠round) (sorry, i don't know how to write beautiful fomular)

we can use pref_min and suf_min to quickly calculate Node that we must update parent value from chill due to tle Here is my code 270747003

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I see newbies solving C damn newbies these days are different breed,back when I was a newbie I couldn't even upsolve C by looking at editorial.But how does their submission looks alike?

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

can anybody write a more intuitive proof for problem D's max of logn sets ?

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hi, I am finding it difficult to understand the solution provided to D. Can someone post a simple solution with an explanation or suggest updates in the existing editorial please?

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

For B I believe we can also "compress" any amount of '0' in a row into a single '0', then simply check if the number of '1's is greater than '0's in the resulting string: 270654643

»
21 месяц назад, скрыть # |
Rev. 5  
Проголосовать: нравится 0 Проголосовать: не нравится

For A, if we do in the reverse way, I think this is a problem like exchanging a new bottle by K bottle caps.

Like given [1, 1, 1, 1, 1, 1, ..., 1] containing n 1s, and we are going to combine at most K items once, and finally derive [n]. The process will be like [1, 1, 1, ..., 1] -> [1, 1, 1, 1, ..., K], containing N-K 1s and 1 K. Our target is to combine all numbers into 1 number, so the real number in the array doesn't matter at all, that it, there remains N-K+1 items to combine.

The maximum number of bottles that can be exchanged is floor((N-1)/(K-1)).

I think this is a classis problem, so you may find video explanations online. I elaborate one here: First give 1 bottle cap to your friend, and every time you exchange K-1 bottle caps with your friend's one, and give the exchanged bottle (cap) back to your friend. You can do this (N-1)/(K-1) times and you will finally exchange floor((N-1)/(K-1)) bottle caps and have remaining (N-1) % (K-1) bottle caps + 1 from your friend.

The difference between A and bottle exchange problem is that if (N-1) % (K-1) + 1 > 1, then you should do the final combine, so the answer is `ceil((N-1)/(K-1)) in this problem.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Problem D got accepted in exacly 3 sec

[submission:https://mirror.codeforces.com/contest/1988/problem/D]

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +10 Проголосовать: не нравится

Pretty surprise to see cartesian tree in $$$E$$$. Maybe it is the first time I see it in CF as well.

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

A felt hard. Came up with DP approach for A during the contest . Normal method was just not striking me.

A using DP
»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится +3 Проголосовать: не нравится

Hello! Does my solution of D get RE because of dfs? 270748754

If yes, is there are way to bypass it nicely?

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

Shouldn't the edi also contain the dp states and transitions atleast instead of just mentioning that you can solve it by dp? (for D)

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Another idea for B is that it is only possible iff the number of "0-streaks" is less than the number of ones.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Please someone explain the bi<=19 part of the editorial in more detail.

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится +8 Проголосовать: не нравится

In fact, problem D has a $$$O(n)$$$ way

Considering that we actually only transfer from the smallest and subsmallest points of each subtree when we transfer, in fact, there are only $$$O(deg)$$$ effective transfer points of a tree point, that is, only the number of selection rounds corresponding to the minimum value of each point, and their mex and mex+1, taking into account this, we only need to maintain the smallest and subsmallest points of each point to implement the $$$O(n)$$$ algorithm.

It comes with an implementation that uses map, which is just for convenience and can be replaced with another $$$O(1)$$$ structure

https://mirror.codeforces.com/contest/1988/submission/270751383

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Could someone provide an explanation of the DP used for Problem D?

Thanks!

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Why does this code in java 270744757 tle but gives ac in c++ 270751728 :( Edit: I see that the c++ code also barely passes maybe i can do better with the transitions

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +8 Проголосовать: не нравится

In fact, problem D has a $$$O(n)$$$ way

Considering that we actually only transfer from the smallest and subsmallest points of each subtree when we transfer, in fact, there are only $$$O(deg)$$$ effective transfer points of a tree point, that is, only the number of selection rounds corresponding to the minimum value of each point, and their mex and mex+1, taking into account this, we only need to maintain the smallest and subsmallest points of each point to implement the $$$O(n)$$$ algorithm.

It comes with an implementation that uses map, which is just for convenience and can be replaced with another $$$O(1)$$$ structure

https://mirror.codeforces.com/contest/1988/submission/270751383

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +2 Проголосовать: не нравится

This codechef problem is harder version of B.

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

I believe my solution for problem E is also O(n), but doesn't require Cartesian tree. It is quite unpleasant to implement and debug though, I couldn't do so during the contest time.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

What's wrong with this idea for D?

There are at most $$$O(\log n)$$$ rounds, so for round $$$j$$$, find the maximum weighted independent set, let it be $$$c_j$$$, then set the values of $$$a_{v_i}$$$ to 0 for each $$$v_i$$$ in the max ind set, and keep doing that until we get all zeroes in a. For round $$$j$$$, add $$$j \cdot c_j$$$ to the answer.

After all rounds, output answer. This fails on test 3 :|

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Problem E can be done by looking at the contribution of each values. If an index is removed then the affected contribution will the - - The contribution from the index itself. This we can find by calculating the left and right index smaller than the value at index. - The contribution coming from the other index that uses this index in their contribution. Here the observation this value will only change if we change the value between the left and right minimum of this index. If we remove left and right, then we have to consider second minimum left and second minimum right respectively and add it accordingly. All the value that is between left and right will only reduce the contribution by 1.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For problem D, am I the only one who decided to use sqrt(n) instead of log2(n) as the bound for b (for safety because I couldn't prove it in contest), only to find out that there's exactly one singular case where sqrt(n) < log2(n)? QAQ

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I came up with DP on subtrees solution for D right after the contest but it got WA on 3rd test. It maintains dp[2][i], the maximum sum of monster points on subtree i we can get in the current round if we skip/kill the root node of that subtree. Can somebody help me understand why that failed?

270745002

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

not come up with '0110110' and got an WA on B :(

»
21 месяц назад, скрыть # |
Rev. 3  
Проголосовать: нравится +5 Проголосовать: не нравится

$$$O(n)$$$ solution in problem E without cartesian tree (although it's long to explain what I'm actually doing): 270758048.

Edit: I miswrote the prev_greater and next_greater, it must be prev_smaller and next_smaller

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +16 Проголосовать: не нравится

I solved E in $$$O(n log(n))$$$

How do you solve if you don't have to remove any element from the array? f(a)
Hint 1
Hint 2
Solution

My Solution

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится -11 Проголосовать: не нравится

I am unable to understand the reason for getting the following error in my code for Problem C 1988C][SUBMISSION:270720573 - Increasing Sequence with Fixed OR

wrong answer Integer parameter [name=a[35]] equals to 1000000000000000000, violates the range [1, 999999999999999999] (test case 102)

The question specifies 1<= n <= 10^18, and that a(i) <= n

Here is my code:- ~~~~~

include <bits/stdc++.h>

using namespace std;

int main() { int t; cin >> t; while(t--) { long long n, n2; cin >> n; n2 = n;

vector<long long> a;
    vector<int> pos;

    int size = 0;
    while(n2>0) {
        if(n2 & 1 == 1) pos.push_back(size);
        n2 = n2 >> 1;
        size++; 
    }

    a.push_back(n);
    for(int i=0; i<pos.size(); i++) {
        long long x = n;
        x = n - pow(2, pos[i]);
        if(x!=0) a.push_back(x);
    }

    cout << a.size() << endl;
    for(int i=a.size()-1; i>=0; i--) cout << a[i] << " ";
    cout << endl;                
}

} ~~~~~

The logic used here simply keep track of the places where the binary digit is 1 starting from position 0 at the right hand side (least significant bit).

Then I simply place 0 one by one in the in the positions where one are placed. For example: n = 1111, then

1111 1110 1101 1011 0111

Just shifting the 0 from right to left across all the positions that have 1, and keeping the position with zeroes as same.

If I have a n = 11100111, then

11100111 11100110 (0 placed at 0th pos from right) 11100101 (0 placed at 1st pos from right) 11100011 (2nd pos) 11000111 (5th pos) 10100111 (6th pos) 01100111 (7th pos)

I create the number with 0 in 6th pos by doing n — pow(2, 6) Which produces the same effect as placing 0 in the sixth position.

Please help me understand the flaw in my logic/code which is causing this unexpected error.

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    bro it's test case 102 with $$$ n = 10^{18} - 1 $$$ and your code outputs:

    42
    423539247696576512 711769623848288256 927942405962072064 963971202981036032 981985601490518016 990992800745259008 999859262511644672 999964815627911168 999982407813955584 999995601953488896 999997800976744448 999999450244186112 999999862561046528 999999931280523264 999999991410065408 999999995705032704 999999997852516352 999999999463129088 999999999932891136 999999999966445568 999999999983222784 999999999995805696 999999999997902848 999999999999868928 999999999999934464 999999999999967232 999999999999983616 999999999999991808 999999999999995904 999999999999997952 999999999999998976 999999999999999488 999999999999999744 999999999999999872 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000 999999999999999999 
    
»
21 месяц назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

why was this failing but if only I changed (n^(1<<i)) part to (((ll)n)^((ll)(pow(2,i)))) it worked

#include <bits/stdc++.h>
#define ll long long
#define fori(n) for(long long i=0; i<n; i++)
#define fori1(n) for(long long i=1; i<n; i++)
#define forj(n) for(long long j=0; j<n; j++)
#define testcases int t; cin>>t; while (t--)
#define ld long double
#define vl vector<long long>
#define vint vector<int>
#define pb emplace_back
#define fast ios::sync_with_stdio(0); cin.tie(0);
using namespace std;
int main()
{
    testcases{
        ll n;
        cin>>n;
        vector<int> s;
        for(int i=60;i>=0;i--){
            if((n>>i)&1)s.push_back(i);
        }
        if(s.size()==1){
            cout<<1<<endl;
            cout<<n<<endl;
            continue;
        }
        cout<<s.size()+1<<endl;
        for(int i:s){
            cout<<(n^(1<<i))<<" ";
        }
        cout<<n;
        cout<<endl;
    }
 return 0;
}
»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone please explain what is going wrong in this solution? I tried to subtract the power of bits which were 1 in n from n.270761320

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Finding it hard to understand Problem D Solution can someone point me to a different tutorial maybe video explanation ?

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

I am looking for help in problem D, because I had an alternative approach (semi-greedy) and can't find any counterexample.

My algorithm goes as follows:
While vertice count > 0:
1. Find a Maximum Weighted Independent Set (MWIS) in the remaining forest.
2. Remove all vertives belonging to MWIS from the forest.

Maybe there is fundamental error in idea, maybe bug in implementation 270734719. Any help would be appreciated. Thanks.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

I was trying to Upsolve D. I read the edi and got the DP approach. I coded it up and was constantly getting TLEs. I optimized a lot (converted map<int, vector> to vector<vector> for the adjacency list, included all fastio, used as less space as possible etc).

I was still getting a TLE, so I had a look at my friend's solution who got an AC in the contest. It was literally the same thing. So I copy pasted it and that also got a TLE. What could be the reason for this ?

Both the codes are literally the same.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Another approach For b if we take all the sequences of 000 and combine them to form a single 0 then The resulting string would only have single 0 and other 1's so if we count no. Of 1's here and if they are greater then no. Of 0's then answer is YES else answer is NO.

Can't think of a proof but it passed all test cases

  • »
    »
    21 месяц назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится 0 Проголосовать: не нравится

    I had the same solution. The proof is pretty simple. Notice that after combining all zeros together you have a sequence where each zero is surrounded by ones. Suppose oneCount > zeroCount, by combining two ones with a zero, you decrease the total amount of 1s and 0s by one. If you repeat this over and over a again, you will reach a point where there is one zero and more than one one. Conversely, it is clear that if the number of zeros is more than or equal to the number of ones, the answer is NO.

    Edit: I just realized you can just choose the whole array :)

»
21 месяц назад, скрыть # |
Rev. 3  
Проголосовать: нравится +2 Проголосовать: не нравится

my clarification for log(n) in problem D, I hope this help someone: suppose in the worst case that you have set of monsters with attack point equal to MX (for example 1e12) and these all nodes connected with all vertices in the tree, then the optimal choice for current round is to select these nodes, then number of nodes now is at least n/2, in the second round suppose the same that you have set of monsters with attack point equal for example MX-1 then best choice to select these nodes, and number of nodes now equal (n/2)/2 ... and so on then after the first round you have n/2 node after the second round you have (n/2)/2 node after the third round you have ((n/2)/2)/2 node .... and so on. then in the worst case there is log(n) rounds.

then now easily you can use dp on tree from any node state: dp[u][r] which is you at node u and at round r transaction: move to each child with round equal any number from 1 to log(n) except current r and choose the minimum

that is my code it may help: https://mirror.codeforces.com/contest/1988/submission/270781650

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by feecIe6418 (previous revision, new revision, compare).

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by feecIe6418 (previous revision, new revision, compare).

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

The description of Jiangly's solution in problem F has somthing wrong, we can't do $$$ans_{i+j}\leftarrow g(j,y)v_{i,x}$$$ without iterating $$$y$$$, and I guess that the translation shoulb be $$$v_{i,y}\leftarrow f(i,x)h_{x+y}$$$ and $$$ans_{i+j}\leftarrow g(j,y)v_{i,y}$$$.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Auto comment: topic has been updated by feecIe6418 (previous revision, new revision, compare).

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

https://mirror.codeforces.com/contest/1988/submission/270807781 where am i doing wrong cananyone please help me

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

guys in the proof of problem D, it is mentioned that:

f(u) ≥ 1 + ∑ [1≤i<u] f(i)

I don't understand this. it is assumed that u is the greatest possible colour in the whole tree. But the same condition might not hold for the direct children of the root. (for their respective subtrees). so why is the recursion formula true?

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится +3 Проголосовать: не нравится

    If I have understood your question correctly you are asking why the direct children can't have the number of days it takes them to be killed = u. Sorry if I have misinterpreted your question.

    Answer: If $$$u$$$ is being defined as the maximum number of days it takes to kill a monster then a node with value $$$u$$$ has to have at least one neighbour ($$$v_j$$$) where the number of days it takes for a node $$$v_j$$$ to die is equal to $$$i$$$ for $$$1 \le i \lt u$$$. The reason for the range being $$$1 \le i \lt u$$$ is because if there was a neighbour $$$v_j$$$ with value equal to $$$i$$$ for $$$1 \le i \le u$$$ then node $$$x$$$ wouldn't be allowed to have the value of $$$u$$$, because it is adjacent to a node $$$v_j$$$ which already has value $$$u$$$, which means that $$$x$$$ would have to take the value of $$$u + 1$$$ which contradicts the claim which states that $$$u$$$ is the largest value.

    Sorry again if I misunderstood your question.

  • »
    »
    19 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Hi. I feel that there are certain logical steps in between before we finally plunge into the recurrence relation. I have tried my best to explain this in this comment.

    Please give this a read and let me know if you see any problem in the explanation.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Can someone say in general where to use min(a,b) instead of fmin(a,b).

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +4 Проголосовать: не нравится

270730886 This was my code for D problem. The time complexity is O(nlogn) in my opinion but it is giving TLE in test case 20. Can anyone identify the issue in my code?

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится +3 Проголосовать: не нравится

How nodes will be destroyed in every round This is one simulation to make you understand that nodes are destroyed in order on which value is assigned to it.
So node having value i will be destroyed in round i.
And way I have assigned values to nodes in such a way that you can make a conclusion that you there is a way to destroy node in more than 3 or 4 rounds.
You will destroy node having assigned value i after node having j value where i>j .

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hello , can anybody explain why bi does not exceed log2(n)+1 . I tried to understand the proof of the editorial but I am having difficulty visualizing it. Any help would be appreciated . Thank you

  • »
    »
    19 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Hi. I also had a very hard time understanding the editorial. I feel I finally have a perspective that explains everything that's written in the editorial. Have tried to put them in this comment. Please refer Part 2.

    Let me know if you see any issue in my explanation.

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Edit : The following proof is wrong!

I have a different proof for maximum rounds in problem D.

Consider a tree $$$T$$$ with $$$n$$$ nodes. We need to show that it can be processed in at most $$$\log_2 n + 1$$$ rounds.

We can always remove at least one vertex. Let us assume it is the centroid of the tree. The tree then breaks into different components of at most $$$\frac{n}{2}$$$ size. We can apply operations on the each component simultaneously and independently.

If $$$f(n)$$$ is the number of rounds for a tree with $$$n$$$ nodes, then we can say: $$$ f(n) \leq f\left(\frac{n}{2}\right) + 1 $$$

By applying this recursively, we get: $$$ f(n) \leq \log_2 n + 1 $$$

Thus, the number of rounds is at most $$$\log_2 n + 1$$$.

Any feedback is appreciated!

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    Thanks for the explanation.

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    I don't think your proof is correct. You are just demonstrating one way to finish the rounds in $$$Log(N)$$$ steps, by choosing centroid at each stage. But how do you ensure that the damage inflicted by other monsters is minimized? What if the centroid inflicts zero damage while other vertices inflict a lot of damage?

    In fact, using your same reasoning, I can show that $$$f(n) \leq 2$$$. In the first round, we remove all the odd levels, and in the second round we remove all even levels. Since I have a way to finish the game in 2 rounds, it doesn't mean that it's optimal.

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

can someone please tell why Greedy don't work for Problem D? -> as in the given tree we can eliminate any number of monsters, with a condition that they should not be adjacent to each other. so in the first turn all monsters will attack and decrement health by total sum of attack power of all monsters but in this move we try to kill all those non-adjacent monsters whose attack sum is maximum and as tree do not contain any cycle therefore there is only two possible scenarios. i used BFS to calculate sum of attack power for both cases and return (total attack power + min of above two cases). -> can anyone please help me to figure out my logical error or what part i am missing, any reply would be appreciated. here's my code link :270855931

»
21 месяц назад, скрыть # |
Rev. 10  
Проголосовать: нравится 0 Проголосовать: не нравится

Could someone point out what's wrong in this construction for E?

My output for TC1:

0 
4 7 5 
19 21 37 17 19 
79 100 72 68 67 106 73 80 

Context — $$$l[i]$$$ stores the closest (to $$$a[i]$$$) smaller element to the left of i. $$$dl[i]$$$ stores the closest smaller element to the left of $$$l[i]$$$. Similar for right.

Important part of the code
»
21 месяц назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

thanks

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

For A, we can solve it like this : Merge n 1s into n and we can merge at most k 1s per time.

So :

  • f(n) = f(n — k) + 1, if n >= k

  • f(n) = 1, if n < k.

It's a $$$O(\frac n k)$$$ solution, I don't know how to convert this expression to an $$$O(1)$$$ expression.

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Can anyone explain why the maximum number of rounds will be logN + 1 in problem D?

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится -10 Проголосовать: не нравится

include<bits/stdc++.h>

define int long long

using namespace std; const int N=3e5+10; int t,n,v[N],a[N],f[N][2],up,x[N],y[N],sum; vector<vector> vec; void dfs(int p) { f[p][1]=v[p]; int len=vec[p].size(); for(int i=0; i<len; i++) { int son=vec[p][i]; dfs(son); f[p][1]+=f[son][0]; f[p][0]+=max(f[son][0],f[son][1]); } } signed main() { cin>>t; while(t--) { sum=0; cin>>n; for(int i=1; i<=n; i++) { a[i]=0; for(int j=0; j<2; j++) { f[i][j]=0; } } vec.resize(N); for(int i=1; i<=n; i++) { cin>>v[i]; sum+=v[i]; } for(int i=1; i<=n-1; i++) { cin>>x[i]>>y[i]; a[y[i]]++; } vector help; for(int i=1; i<=n; i++) { if(a[i]==0) help.push_back(i); } int len=help.size(); for(int i=0; i<len-1; i++) { int tem=help[i]; for(int j=1; j<=n; j++) { if(x[j]==tem&&a[y[j]]>1) { a[y[j]]--; swap(x[j],y[j]); break; } } } for(int i=1; i<=n-1; i++) { vec[x[i]].push_back(y[i]); } for(int i=1; i<=n; i++) { if(a[i]==0) up=i; } //cout<<"---------"<<up<<endl; dfs(up); cout<<sum-max(f[up][1],f[up][0])+sum<<endl; vec.clear(); } } //2 1 //1 4 //3 2 //5 3 //2 6 //7 5 //16 8521 1428 4732 0223 //2 1 //1 4 //3 2 //5 3 //2 6 //7 5
why my code is wrong

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Note that in an optimal arrangement, bi=mex(j,i)∈Ebj.

okay, for root node, this is definitely true. but can someone give me the proof for every node?

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    can you please explain me what is bi=mex(j,i)(=Ebj here... i am not able to think or understand what it is.

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    Let's call $$$\displaystyle m_i = \mathop{\mathrm{mex}}_{(j,i) \in E} b_j$$$.

    If $$$b_i \lt m_i$$$, then $$$b_i = b_j$$$ holds for some $$$j$$$, which is not allowed (in the round $$$b_i = b_j$$$, the monster $$$i$$$ and $$$j$$$ are killed at the same time, but there's an edge between $$$j$$$ and $$$i$$$). If $$$b_i \gt m_i$$$, the monster $$$i$$$ can be killed in an earlier round (specifically, in the round $$$m_i$$$), because no other adjacent monster is killed in the round $$$m_i$$$, so this $$$b_i$$$ is not optimal. Therefore, $$$b_i = m_i$$$.

»
21 месяц назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

For Problem C the solution for testcase 1 has to be 2 i.e 0, 1

It is because the bitwise OR of 0 and 1 is also 1, so the answer for 1 is 2 and the sequence is 0 1. Please clear my doubt...

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Thks for the cool round!

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For D, any ideas on how to approach this when the graph has cycle?

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Hello! Can someone please explain why the upper bound for the number of rounds to kill all the monsters is not 4?

What makes me think of this is because of Appel and Haken's 4 Color Theorem for loopless planar graphs. Any help and advice is greatly appreciated!

  • »
    »
    21 месяц назад, скрыть # ^ |
     
    Проголосовать: нравится 0 Проголосовать: не нравится

    You are ignoring the damage that the monsters who are not killed in round 1 would inflict. In fact, according to what you are thinking, the upper bound should be 2 (why not kill monsters at odd level in round 1 and monsters in even levels in round 2?). But this has the same flaw as the greedy solution in knapsack, i.e, keep picking highest valued items as long as the total weight is less than the capacity.

    But why is the upper bound $$$O(Log(n))$$$ regardless of the monster's damage? I talk about it in my video editorial

»
21 месяц назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Aah ok

»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

My solution to problem E, using monotonic stack, prefix sum, and binsearch.

First, notice we can use a monotonic stack to calculate $$$f(a)$$$. The idea is for each $$$i$$$ we can store the sum of all ranges with right endpoint at $$$i$$$, and quickly update from $$$i$$$ to $$$i+1$$$. Thus, if we go through the whole array, we will have the answer.

Specifically, keep a stack $$$s$$$ where each element is an index $$$i$$$ (representing $$$a_i$$$), and store $$$\sum_{1 \le i \le sz(s)} a_{s_i} \cdot (s_i - s_{i-1})$$$, which is the sum of all ranges with right endpoint at $$$i$$$. For each $$$i$$$ from $$$1$$$ to $$$n$$$, pop any indices $$$j$$$ from $$$s$$$ where $$$a_{s_j} \gt a_i$$$, then push $$$i$$$ into the stack, updating the sum accordingly.

Notice that the stack is monotonically increasing in value and index. Also notice that we can take a prefix sum of our stack $$$s$$$ from earlier: Additions/removals will still take $$$O(1)$$$ asymptotically.

This will give the answer for $$$a$$$. Call the index of the element we remove $$$i$$$. Now, notice that the answer for $$$b$$$ is quite similar to the answer for $$$a$$$ — we have to make $$$4$$$ adjustments from the answer for $$$a$$$ to get the answer for $$$b$$$:

  1. Subtract the range $$$[i, i]$$$, or simply $$$a_i$$$.
  2. Subtract all ranges $$$[l, i]$$$ except $$$[i, i]$$$.
  3. Subtract all ranges $$$[r, i]$$$, except $$$[i, i]$$$.
  4. Recalculate all ranges $$$[l, r]$$$ where $$$a_i$$$ is the min element, where $$$l \neq i$$$ and $$$r \neq i$$$.

#1 is trivial.

For #2, we can binary search for $$$a_i$$$ on the stack (since it is sorted). Call the resultant index on the array $$$left$$$. Then for any range $$$[l, i]$$$ where $$$left \le l \lt i$$$, the value is $$$a_i$$$. For the ranges $$$[l, i]$$$ where $$$0 \le l \lt left$$$, we can take the appropriate value from our prefix sum.

For #3, we can reuse the strategy for #2, keeping a backwards stack and prefix sum that starts from the end and goes towards the front.

For #4: I think the algorithm makes more sense if you think about it in your head... Essentially, for each element of the left stack, we binary search on the right stack and add values to the answer accordingly. We also need to subtract $$$a_i * (a_i - l) * (r - a_i - 1)$$$. Even though a single operation could go through the whole stack, it is still $$$O(\log n)$$$ per element asymptotically!

Implementation was very hard for me. 280260483

»
19 месяцев назад, скрыть # |
Rev. 2  
Проголосовать: нравится 0 Проголосовать: не нравится

Problem D — The Omnipotent Monster Killer


Part 1 - DFS

Part 2 - Bound on maximum number of rounds

We perform the DFS trying each monster to get killed at each of log(n) rounds.

Time complexity
»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For Tutorial of problem-D, "depending on whether you use prefix/suffix maximums to optimize the taking max part." should be "depending on whether you use prefix/suffix maximums to optimize the taking min part.".

»
17 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Why does this TLE for D?

#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
using namespace std;
#define int long long

// dp/trees

int findtime(int node,int takentimestamp,int par,int maxtime,vector<vector<int>>&adj,vector<vector<int>>&dp,vector<int>&damage)
{
    if(dp[node][takentimestamp]!=(-1))
    {
        return dp[node][takentimestamp];
    }
    int ans=LLONG_MAX;
    for(int i=1;i<=maxtime;i++)
    {
        int tempans=i*damage[node];
        if(i==takentimestamp)
        {
            continue;
        }
        for(auto j:adj[node])
        {
            if(j==par)
            {
                continue;
            }
            tempans+=findtime(j,i,node,maxtime,adj,dp,damage);
        }
        ans=min(ans,tempans);
    }
    dp[node][takentimestamp]=ans;
    return dp[node][takentimestamp];
}

void solve()
{
    int n,u,v;
    cin>>n;
    vector<int>damage(n);
    for(int i=0;i<n;i++)
    {
        cin>>damage[i];
    }
    vector<vector<int>>adj(n,vector<int>());
    for(int i=1;i<n;i++)
    {
        cin>>u>>v;
        u--,v--;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    int maxtime=log2(n)+1;
    vector<vector<int>>dp(n,vector<int>(maxtime+1,-1));
    int mintime=findtime(0,0,-1,maxtime,adj,dp,damage);
    cout<<mintime<<"\n";
    return;
}

signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin>>t;
    while(t--)
    {
        solve();
    }
    return 0;
}