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

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

2062A - String

Idea: StarSilk. Solution: StarSilk. Preparation: SSerxhs, StarSilk.

Rate this problem
Solution
Code (C++)
Code (Python)

2062B - Clockwork

Idea: StarSilk. Solution: StarSilk. Preparation: SSerxhs, StarSilk.

Rate this problem
Solution
Code (C++)
Code (Python)

2062C - Cirno and Operations

Idea: Yakumo_Ran. Solution: Yakumo_Ran. Preparation: Yakumo_Ran, SSerxhs, mejiamejia.

Rate this problem
Solution
Code (C++)
Code (Python)

2062D - Balanced Tree

Idea: StarSilk, SSerxhs. Solution: StarSilk, SSerxhs. Preparation: SSerxhs.

Rate this problem
Solution
Code (C++)
Code (Python)

2062E1 - The Game (Easy Version)

Idea: Yakumo_Ran. Solution: Yakumo_Ran. Preparation: Yakumo_Ran,mejiamejia,SSerxhs.

Rate this problem
Solution
Code (C++)
Code (Python)

2062E2 - The Game (Hard Version)

Idea: SSerxhs. Solution: StarSilk,SSerxhs,PaperCloud,fallleaves01. Preparation: SSerxhs,mejiamejia.

Rate this problem
Solution
Code (C++)

2062F - Traveling Salescat

Idea: StarSilk. Solution: StarSilk. Preparation: SSerxhs, StarSilk.

Rate this problem
Solution
Code (C++)
Code (Python)

2062G - Permutation Factory

Idea: StarSilk. Solution: StarSilk. Preparation: StarSilk, SSerxhs.

Rate this problem
Solution
Code (C++)

2062H - Galaxy Generator

Idea: StarSilk. Solution: StarSilk. Preparation: StarSilk.

Rate this problem
Solution
Code (C++)
  • Проголосовать: нравится
  • +93
  • Проголосовать: не нравится

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

In Editorial of C :

Unable to parse markup [type=CF_MATHJAX]

Fixed

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

Unable to view Editorial for problem C

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

We're not beating the speedforces allegations with this one!

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

D>>>>>>>>>>>>>>>>>>>>>E1

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

nah, no way, I got C wrong cus I forgot to use LL

303138777 and 303120425

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

First time i solved a b AND c in div1+2. Hope to get +ve delta :). thank you!

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

for B should the condition be ti>2max(i−1,n−i)

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

I think for C, one could additionally use the fact that in an array of length $$$n$$$, the sum of differences is $$$a_n - a_1$$$. Thus if $$$a_n \lt a_1$$$, we reverse else not.

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

The editorial for C and D is not very clear. What does fa mean in D?

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

not convinced(or did not fully understand) the proof of problem C. please help.

Assuming that in the optimal answer the sequence of operations is 1211121221.

Consider swapping two adjacent operations: 12→21 ... which is equivalent to taking the negation.

so, are we proving that instead of doing 1211121221 we can simply do 1111112222? Then we may need to do negation of all elements based on number of 12 operation swaps?

and of course since 111111 -> no-op we might as well only do 2222?

I think I understand now. However please let me know if I understood something incorrectly. thanks!

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

    Sorry for mixing up 1 and 2. It has been corrected now, and your understanding is correct.

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

      But why doesn't it matter what the array looked like before you perform operation 1 or 2? The 12 -> 21 negating sum condition only applies to the sum right. But we can get different sums by performing operation 2 on different arrays (different elements at each index). Am I wrong?

      For example, applying 2 to 1212 gives you a different individual elements than applying it to 2121. Wouldn't it?

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

        Think 2121 gives same output as 11

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

        Yeah, I was wondering exactly that, and the editorial lacks so much explanation that you really can't assume that the negative of the array won't generate possibly new (and larger) sums after you apply some other operations on it. That's why I wrote a comment explaining it with proofs of (almost) everything (except trivial things). I think you could like my explanation, so, please, take a look at my comment (somewhere below on this comment section).

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

I feel like the editorial for B is incomplete, especially for beginners. The most crucial part of the solution is that there never exists a part of the sequence that goes: {i...i+1 ...i... i+1} without visiting both ends of the array which allows one to show that the only optimal sequence is one in which we bounce back and forth from opposite ends of the array.

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

    What does this mean?

    there never exists a part of the sequence that goes: {i...i+1 ...i... i+1} without visiting both ends of the array

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

      Imagine we visited {...2, 3, 2, 3...} at some point in our traversal. This is sub-optimal as the clocks after the first two moves are the same as after the fourth moves, but in the later all other clocks are two less. Hence we should delete the second {2,3};

      This logic can be extended to any subsequence of the form {i, i+1, ...i+k,i+k-1,...i+1, i, i+1, ... i+k} where we can delete the everything after the first i+k and get a strictly better solution.

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

What is meant by "Since 2 does not change the sum of the sequence" in C's editorial? Doing the operation changes the sum right?

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

dp solution of problem C[Check303116516..]

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

B>>>>>>>>>C

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

The editorial for D is made for people who have successfully solved the problem in the contest. The editorial is not clear at all !

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

    Even I feel so,Can Someone Please provide a more detailed explanation.

    • »
      »
      »
      19 месяцев назад, скрыть # ^ |
       
      Проголосовать: нравится +32 Проголосовать: не нравится
      • The operation can be rephrased as follows: choose any edge in the tree, consider the two subtrees resulting from removing that edge, choose one of those subtrees, and increment all values in it by 1.

      • Consider any assignment of initial values to the nodes. For any two nodes connected by an edge, if they have different initial values, they can only become equal if we perform the operation selecting the edge between them, and incrementing the subtree of the smaller node.

      • Now, consider what the value of node i will be in the end. We can find this value by rooting the tree at i. The final value after the tree becomes balanced will be val[i] + sum(max(0, val[u] — val[par[u]])). Basically if val[par[u]] < val[u], we will need to increment everything above u.

      • We can prove that actually rooting at any node j != i will yield the same result as i. One way to prove this is by considering what happens to the result when we move from i to a neighbor.

      • Finally, this means we can just root arbitrarily, and greedily minimize sum(max(0, val[u] — val[par[u]])).

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

    I think it's quite clear for me. Can u explain which part made u confused pls?

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

Please don't use symbols that are hard to understand in editorials like in E1 for example: w,dfn,nfd,pre,suf,low

I am really trying to understand the solution, but I can't really fathom it due to them.

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

Can someone tell me why it doesn't get TLE? I literally brute-forced the operations and memoized the array itself. Submission Thanks

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

    All the second operation does is multiply the array by -1 after the next operation of the first type, this means applying the second operation twice undoes itself no matter how many operations of type one are performed inbetween. Hence you only have 2*N states.

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

I somehow misread the problem B and thought we need to spend an additional second if we want to reset the clock. Does anyone know if this version of the problem is solvable?

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

Below I explain the solution to exercise C, doing exactly what the editorial didn't do.

Let's call the reverse instruction as '1' and the difference instruction as '2'. Let's create a new instruction, the "negative" instruction, that I will call from here on as '3'. That instruction multiplies each element of the input array by -1.

Theorem 1) Applying operation 1 two consecutive times is the same as not doing anything (proof omitted)

Theorem 2) Applying operation 3 two consecutive times is the same as not doing anything (proof omitted)

Theorem 3) Applying operation 1 does not change the sum of the input array (proof omitted)

Theorem 4) Applying operations "12" to a sequence is the same as applying operations "231".

Proof:

Let the input array be [a1, a2, a3, ..., an]. Applying "12" on it leads to:

After 1: [an, a(n-1), a(n-2), ..., a1]

After 2: [a(n-1)-an, a(n-2)-a(n-1), ..., a1-a2]

Applying "231" to [a1, a2, a3, ..., an]:

After 2: [a2-a1, a3-a2, ..., an-a(n-1)]

After 3: [a1-a2, a2-a3, ..., a(n-1)-an]

After 1: [a(n-1)-an, a(n-2)-a(n-1), ..., a1-a2]

So, the sequences of operations "12" and "231" are equivalent.

Theorem 5) Applying operations "23" to a sequence is the same as applying operations "32".

Proof:

Let the input array be [a1, a2, a3, ... an]. Applying "23" on it leads to:

After 2) [a2-a1, a3-a2, ..., an-a(n-1)]

After 3) [a1-a2, a2-a3, ..., a(n-1)-an]

And applying "32" to [a1, a2, a3, ... an]:

After 3) [-a1, -a2, -a3, ..., -an]

After 2) [a1-a2, a3-a2, ..., a(n-1)-an]

So, the sequences of operations "23" and "32" are equivalent.

===================

With those theorems in hand, let's solve the exercise.

Let s be any sequence of operations that leads to the maximum possible sum. For example, s may look something like this:

s = 11112221212212112111

According to Theorem 1, I can remove every pair of consecutive 1's, which would give me the following sequence:

s = 222121221221

According to Theorem 3, I can remove the last 1 of the sequence:

s = 22212122122

Now, from the left to the right of the sequence, let's change any appearance of "12" to "231". That won't change the final sum because Theorem 4 says those instructions are equivalent. If, while changing "12" to "231", we end up with consecutive 1's, we simply remove them (because of Theorem 1). If we end up with a 1 on the end, we simply remove it (because of Theorem 3). Below I simulate that process:

s = 22212122122

s = 222231122122 (Theorem 4)

s = 2222322122 (Theorem 1)

s = 22223222312 (Theorem 4)

s = 222232223231 (Theorem 4)

s = 22223222323 (Theorem 3)

As you can see, we ended up with a sequence made only of 2's and 3's. Now, let's apply Theorem 5 several times and move all the 3's to the end:

s = 22222222333

And now let's remove consecutive pairs of 3's, because Theorem 2 allows us to:

s = 222222223

This simulation gives us a general idea of what any optimal sum sequence looks like: it is either:

  • An empty sequence (s = "")

  • A sequence of 1 or more 2's followed by none or only one 3 (s = "222...2223", s = "22...2", etc)

Now, our algorithm should simply try all of those sequences and grab the one with the highest sum, as shown here: (303162845)

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

is there any solution for E2 using small to big and segment tree

this is my attempt for this problem. if anyone can explain why my code gives me wa or gives a corner case for my code thanks.

https://codeforces.me/contest/2062/submission/303162086

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

Sadly i was not aware that if we resubmit a accepted qestion then the time of resubmition will be considered for that problem and my rank droped by 4000.

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

Can anyone recommend me some resources to solve E1? I got the idea in the contest but the editorial isn't clear about how to achieve the idea. Looking at others solutions, I feel like there's a gap in my knowledge somewhere on the topic.

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

I didn’t solve D just because I didn’t consider the tree with only one point, which resulted in me doing nothing for the last hour. That's funny.

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

Thanks for the excellent contest. Problems D,E and F are all intersting!

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

How is the construction of array $$$a$$$ in Problem D’s editorial optimal?

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

    Yeah I've got it figured out today. Here's my train of thoughts:

    The goal is to minimize

    $$$ans:=a_1+\sum_{u=2}^{n}\max\{0,a_u-a_{\text{fa}[u]}\}$$$

    We could first try finding this value for all the other nodes of the tree before getting to the root.

    $$$ans_u:=a_u+\sum_{v|u\in anc_v}\max\{0,a_v-a_{\text{fa}[v]}\}$$$

    Setting $u=1$ yields $$$ans=ans_1$$$.

    We try to find the minimum of $$$ans_u$$$ for every node $$$u$$$ first. Assume that we have fixed $$$a_v$$$ for all $$$v$$$ is in the subtree of $$$u$$$ when we fix node $$$1$$$ as root of the tree.

    First try setting $$$a_u$$$ to $$$\max\{a_v\}$$$. There's no point in increasing $$$a_u$$$ as doing so would only increase $$$ans_u$$$. So $$$a_u\leq\min\{r_u, \max\{a_v\}\}$$$.

    Decreasing $$$a_u$$$ by $$$1$$$ would result in a increment of $$$1$$$ in $$$\max\{0, a_v-a_u\}$$$ for at least one of $$$v$$$ for $$$v$$$ that satisfies $$$\text{fa}[v]=u$$$.

    Thus to minimize $$$ans_u$$$ when all $$$a_v$$$ is fixed for every $$$v$$$ in the subtree of $$$u$$$ except for $$$u$$$ itself, it is optimal for $$$a_u$$$ to take the value of $$$\max\{l_u, \min\{r_u, \max\{a_v\}\}\}$$$.

    It is optimal to construct $$$a$$$ such that $$$ans_u$$$ takes its minimum for every $$$u$$$. If we can get the value of every node in the subtree of $$$u$$$ to be $$$ans_u$$$, then with one operation in which we increase the value of all nodes in subtree of $$$u$$$ by $$$1$$$ while considering $$$\text{fa}[u]$$$ as the root of the tree, we could achieve the same value for $$$ans_1$$$ when $$$ans_u$$$ is not at its minimum. In other words, minimizing $$$ans_u$$$ wouldn't increase $$$ans_1$$$.

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

Can someone who have solved E1 tell how they solved it and came to the conclusion their method was right?

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

    At first we need to sort all node by their weight, then our strategy is choosing second biggest node (when it sorted by weight), and checking if in its subtree contains all bigger weight node or not, if not we will choose it, next player will choose the biggest, so there will be no other option, so we win. If it contains all, just check next smaller weights, until we find answer. If we dont find it, then there no answer. I solved that intuitively, that's why I wasn't sure if its correct or not :)

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

Problem D: Anyone getting Runtime Error in Test 8? Please help me how my solution got accepted in 7 test cases but runtime error in test 8?

https://codeforces.me/contest/2062/submission/303196494

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

How does the C++ solution of D work?
Why does this line erase(e[v], u); not TLE?
Should it not be $$$O(n^2)$$$?

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

why O(n^2) gives TLE in E1, even when time limit is 4 sec ?


const int N=1e6+5; vector<int> tree[N]; int down[N]; int up[N]; int id; bool visited[N]; int p[N]; void dfs(int u) { if(visited[u])return; down[u]=++id; visited[u]=1; p[id]=u; for(auto it:tree[u]) { dfs(it); } up[u]=++id; } bool comp(pair<int,int>&a,pair<int,int>&b) { return a.first>b.first; } void solve() { int n; cin>>n; for (int i=1; i<=n; i++) { tree[i].clear(); id=0; visited[i]=0; } vector<int>wt(n+1,0); for(int i=1;i<=n;i++) { cin>>wt[i]; } for(int i=0;i<n-1;i++) { int x,y; cin>>x>>y; tree[x].push_back(y); tree[y].push_back(x); } dfs(1); vector<pair<int,int>>ans; for(int i=1;i<=n;i++) { int l=down[i]; int r=up[i]; for(int j=1;j<=id;j++) { if(j>=l && j<=r)continue; if(p[j]<=n && wt[p[j]]>wt[i]){ ans.push_back({wt[i],i}); } } } for(int i=0;i<=3*n;i++) { p[i]=0; } if(ans.size()==0) { cout<<0<<endl; return; } sort(ans.begin(),ans.end(),comp); cout<<ans[0].second<<endl; }
»
19 месяцев назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

Anyone have material For understanding E1 problem i see sol but that is beyond my understanding since some are using eulertour or something can someone provide problem resource for this pls

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

E1 editorial says "Additionally, we can enumerate the nodes in descending order of wi and maintain their lowest common ancestor (LCA). If the LCA of all v satisfying wv>wu is not a descendant of u, then there must exist a node v outside the subtree of u that satisfies wv>wu."

what if there are n/2 nodes with maximum w[v] and we need to check each one of them with every other w[u] to find the answer and exactly the last one we check is the answer?

isn't it O(n^2lg)? or even O(n^2)?

can someone explain if I'm wrong?

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

Don't know if anyone can't understand the implementation of E2 from official editorial but here is my own code, based totally on what the editorial said, using LCA and basic data structures. maybe it's easier to understand?

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

Does anyone have proof for why solution for D actually works?

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

    imho, I don't see myself looking at D and thinking ohh well this should work. (maybe my skill issue).

    Apart from that I wanted to say that I loved problem F.

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

    I will explain how i approached the problem:

    Lets root the tree at node $$$1$$$. We need to find the minimum value $$$V_u$$$ for the subtree of some node $$$u$$$. (we can always increase the value later if we need)

    Assume the subtree of all of the children of $$$u$$$ have an equal value $$$V_i$$$. we have two cases:

    • $$$V_i \leq R_u$$$, we can just increase that subtree till $$$L_u \leq V_i$$$

    • $$$V_i \gt R_u$$$, we need to increase all of the tree except that subtree, the final answer increases by the difference $$$V_i - R_u$$$ and $$$V_i$$$ "decreases" till its at most $$$R_u$$$ (the only thing that changes is their relative difference)

    The minimum value of the node $$$u$$$ is the maximum value among $$$V_i$$$ and the minimum value of a leaf is just $$$L_u$$$.

    Code

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

      The thing that is bugging me is why choosing any root for this operation is fine?

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

        Consider an operation: root the tree at node $$$u$$$ and increase the subtree of node $$$v$$$ ($$$u \neq v$$$). we can always move the root $$$u$$$ towards $$$v$$$ as long as $$$u \neq v$$$ and the operation will have the same effect.

        So the operations can be simplified to two adjacent nodes (an edge) or equal nodes (which just increases the entire tree).

        That means if we root at any node $$$u$$$, the operation can be done on some edge and increase either the entire tree, the entire tree except a subtree or only the subtree. so we can just consider one root.

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

Hello, pls someone help me to find mistake in my solution of D: My idea is that I am taking a leaf and its parent and trying to make them equal in minimal amount of steps, then just deleting leaf, cause it will behave like its parent

my submission

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

the editorialist must explain in the D, why taking any node as root for the greedy strategy yields in same answer.

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

The DP of F is fun, but I have a question. How do you approach the required transformation of the max? Are these transformations common? I don't think I can come up with one even if I think about it for a week. I wonder how the rankers came up with it.

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

    +1,I have absolutely no idea how to come up with this transformation. It's like magic...

  • »
    »
    19 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +23 Проголосовать: не нравится
    1. It is a fairly standard transformation of rotating the plane by 45 degrees

    2. It is not necessary to solve the problem this way, you can argue the same without ever rotating the plane.

    The actual observation is that a[i] + b[j] >= a[j] + b[i] means that a[i] — b[i] >= a[j] — b[j], and hence sorting by a — b is useful. You dont need a transformation to see this, and this was my first observation in the problem (not transforming the coordinates but observing when max takes one of the terms instead of the other)

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

    I had the following thought process: Place $$$2n$$$ points on the plane at positions $$$(a_i,b_i)$$$ and at $$$(-b_i,-a_i)$$$. If you take the distance metric that takes the max of the delta x and y, and calculate the distance between a positive and a negative point it is exactly the distance in the problem. Now because we have "king" distance it is a natural trick to turn the plane 45 degrees to convert to manhattan distance, as independence of coordinates could simplify things. From here the rest of the editorial eventually follows.

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

      Can you explain the last two senetences?
      How can we "convert" king distance to manhattan distance by rotating the plane?

      If we have a point with coordinates (x,y) distances from (0,0) (some ai and bi could be 0, says the problem) are king: max(x,y) and manhattan: x+y, aren't they?
      By rotating them by 45 degrees coordinates will be ((x-y)/sqrt(2),(x+y)/sqrt(2)). Distances from (0,0) are king: max((x-y)/sqrt(2),(x+y)/sqrt(2)) and manhattan: x*sqrt(2).
      First(before rotation) king distance is not like second(after rotation) manhattan distance. Furthermore, neither of the 4 distances are matching.

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

    The initial formula is kinda ugly, and a natural thing to do is to try to make one side of the formula depended only on $$$i$$$, and the other only on $$$j$$$.

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

in problem D

when the values are fixed its easy to prove that any root works but since L , R change , how to prove it'll never affect the final answer ?

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

In problem F

How to prove that we need to have 2 vertexes start and end, after that, the rest just appear accord increasing of index (after sorted) ? I got stuck that the path is just a permutation :(

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

    Because all remaining cities contribute x twice, this permutation does not affect x's contribution. Put all cities on the number line according to y, and the problem is like you need to walk from a fixed starting point to a fixed ending point on the number line, and then there are several points on the number line that need to be passed through. And y's contribution to the answer is the total distance you have traveled on the number line. This way, it is easy to see that this movement method obtains the shortest distance.

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

      Oh thank you so much.

      I just focus to ai and bi, not xi and yi

      But is there any proof according just ai and bi ? Because I think the transfer to xi and yi is quite .... magic and it's hard to me to think about the solution which have xi and yi

      Thank you so much :D

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

It seems 3 sample inputs of problem H can form 3 quarters of a QR code. Is it a puzzle to a valid QR code?(after filling the missing one) (just curious)

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

maybe i am too retarded to comprehend the problem C solution. Can anyone give me the more detailed explanation about it??

So, i imagine it as like this. The optimal solution could be displayed as an array with elements of the array is either 1 or 2.

Let's call it arr with size of k. So, it'll be like 12111122111.... something

Now, we know that swapping a 12 to become 21 is the same as doing multiplication by -1 to the result. But, i don't see how this couuld works!!

Let's say that we have calculate the sum of the array 12111. Changing it to become 21111 doesn't fkin means that i could multiply it by minus 1, right???

So, where's the correlation between the actual answer and us knowing the correlation between swapping elements and negating the answer ???

Please, my fucking brain has fried for even thinking it.........

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

    first type of operation only changes sign of sum of $$$a$$$
    for example if there are two adjacent elements $$$a_1..x,$$$ $$$y..a_n$$$
    if you do 1 type opn $$$a$$$ will become $$$a_n..y,$$$ $$$x..a_1$$$
    now if you do 2 type opn this adjacent pair contribute $$$x - y$$$
    but if you didn't performed 1 type opn it will contribute $$$y - x$$$
    so you have to check only abs(sum) for all lengths n to 1

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

In D, why the best ans is the time of root is 1? how about other condition? if can not, should we use change root dp to fix it?

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

can someone explain to me problem b (im not understanding the tutorial)

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

Has some one noticed that there are contradictory part of E2's explanation?

Or v must prevent Daiyousei from choosing this u.In other words, either wv≥wu, or u is within the subtree of v" but we know that u represent Daiyousei's choice and v represent Cirno's choice ,which means it is impossible for u is within the subtree of v