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

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

Thanks for participating!

2067A - Adjacent Digit Sums

Tutorial
Submission

2067B - Two Large Bags

Tutorial
Submission

2067C - Devyatkino

Tutorial
Submission

2067D - Object Identification

Tutorial
Submission

2067E - White Magic

Tutorial
Submission

2067F - Bitwise Slides

Tutorial
Submission

2066D1 - Club of Young Aircraft Builders (easy version)

Tutorial
Submission

2066D2 - Club of Young Aircraft Builders (hard version)

Tutorial
Submission

2066E - Tropical Season

Tutorial
Submission

2066F - Curse

Tutorial
Submission
Разбор задач Codeforces Round 1004 (Div. 1)
  • Проголосовать: нравится
  • +110
  • Проголосовать: не нравится

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

thank you for the quick editorial, questions were tricky.

I need to understand official approach, hoping to get some proofs of correctness

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

    Idea for B — Two Large Bags

    Now re-consider this problem with the following idea:

    For each number i in the array, count[i] should be even. You are allowed to perform operations on the counts. The allowed operation is : if count[i] >= 2, then you can perform

    Operation: count[i + 1]++ and count[i]--.

    Key Idea

    Even Pairing Requirement: Each number i must ultimately appear an even number of times so that the numbers can be split equally between the two bags.

    Pushing Numbers Forward:

    If count[i] > 2, one might think to push all count[i] - 1 copies to i + 1. However, there is a catch:

    If you push count[i] - 1 numbers, then there will be only 1 copy of i left, meaning i will not be paired with any other i. Therefore, you only need to push count[i] - 2 copies to i + 1, leaving behind a pair of i.

    Greedy Approach:

    You have to carry these extra numbers as far forward as possible because they can combine with any upcoming larger number and form a pair with that number. TC : O(n) SC : O(n).

    #include <bits/stdc++.h>
    
    using namespace std;
    
    #define ws ' '
    #define newl '\n'
    #define ll long long
    #define pb push_back
    #define all(x) x.begin(), x.end()
    #define _sz(x) (int) x.size()
    #define Yes cout << "Yes\n"
    #define No cout << "No\n"
    
    
    void solve() {
        int n;
        cin >> n;
        vector<int> hash(n + 1, 0);
        for (int i = 0, x; i < n; ++i) {
            cin >> x;
            hash[x]++;
        }
    
        for (int i = 1; i < n; i++) {
            if (hash[i] > 2) {
                hash[i + 1] += hash[i] - 2;
                hash[i] = 2;
            }
        }
    
        for (int i = 1; i <= n; i++) {
            if (hash[i] % 2 == 1) {
                No;
                return;
            }
        }
    
        Yes;
    }
    
    int main() {
        ios::sync_with_stdio(false); cin.tie(__null);
        
        int t = 1;
        cin >> t;
    
        for (int _ = 0; _ < t; _++) solve();
    
        return 0;
    }
    
    
»
15 месяцев назад, скрыть # |
 
Проголосовать: нравится -52 Проголосовать: не нравится

good contest , bad contest

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

I reached CM!

The best contest i've ever particpated!

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

please make editorial for problem D in English

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

How was it supposed to be deduced for A that 'n' is supposed to be a 'positive integer' only? The problem specified for 'n' to be an 'integer' which allows a larger set of valid pairs. More precisely for each currently accepted (x, y), (y, x) should also be a valid pair.

Or am I missing some detail?

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

tricky but insteresting questions!

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

sevlll777 Problem D (Div2) or Problem A (Div1)'s Editorial is in Russian language only.. Please make it available in English !!

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

Interesting and exciting.Love it!

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

Is there a problem in the interactor of Div. 1 A (Div. 2 D) Object Identification? This submission 305637703 passes the sample locally but gets WA 1.

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

Can anybody explain why this doesnt work for A?

void solve(){
	ll x,y;
	cin >> x >> y;
	if(x<y){
		if(x==y-1) cout << "YES";
		else cout << "NO";
	}
	else{
		if(x%9==y%9-1) cout << "YES";
		else cout << "NO";
	}
}
  • »
    »
    15 месяцев назад, скрыть # ^ |
     
    Проголосовать: нравится +1 Проголосовать: не нравится

    See you have a integer number n let say it consist ABCDEF where A,B..F are digits

    Thing about the two case:

    • Case 1: Where unit digit (here F belongs to [0,8]) n+1 make it belongs to [1,9] that mean the whole structure of number n would remains constant except the unit digit F so the sum would increase just by one x = A+B+C+D+E+F y = x + 1

    • Case 2: Where unit digit of n is 9 now n+1 will make unit digit 0 and carry 1 will be forward to E, again thing of two case E belongs to [0,8] or E == 9, if case 1 then simply it will add up 1 and stop other wise make digit E = 0 for n+1 and forward that carry to D.

    so you got a sum x for n, for n+1 you are going to get some zeroes in place contiguous 9 from unit place (let say k no of 0 replacing k 9's) and finally adding 1 to very first non 9 digit.

    so y = x- k.9 + 1

    clearly visible (x + 1- y) must be divisible by 9 by taking care that (...) is >= 0.

    That's it.... I hope it is helpful and easy to understand pardon my bad English

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

Here's a combinatorial solution for D1.

Let the number of planes launched from $$$i^{\text{th}}$$$ floor be $$$u_i$$$, note that $$$u_{n} = c$$$.

Now corresponding to this case in the original dp recursion solution we get the term $$$\prod_{i=1}^{n-1} \binom{c}{u_i}$$$

So the final answer is just sum over this expresion as $$$u_i$$$ ranges over all possible values constrained by $$$0\le u_i \le c$$$ and $$$\sum_{i=1}^{n-1} u_i = m-c$$$.

Now this is equivalent to a counting problem where we have $$$c(n-1)$$$ distinct objects divided into $$$n-1$$$ types with $$$c$$$ objects of every type and we want to choose a total of $$$m-c$$$ objects. The above expression occurs when we count by first deciding number of objects of each type and then choosing the objects per type. Instead we can directly choose the $$$m-c$$$ objects.

Hence the answer is

$$$\displaystyle\binom{c(n-1)}{m-c}$$$
  • »
    »
    15 месяцев назад, скрыть # ^ |
    Rev. 2  
    Проголосовать: нравится +135 Проголосовать: не нравится

    Version without needing to know the DP:

    Choose the throw order for the top $$$k$$$ floors.
    For the floor below, you get $$$c$$$ choices of either throwing your plane or letting a plane fall from above.
    This happens for all floors except the top floor (which must throw $$$c$$$ planes).

    So in total there are $$$c\cdot(n-1)$$$ choices, and $$$m-c$$$ must be chosen to actually throw planes, thus $$$\binom{c(n-1)}{m-c}$$$.

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

    No matter consider in the DP way or not, the process of modeling, considering in the order from 1st floor to n-1 floor and noticing the numbers of what they've chosen is a constant, really matters.

    Merging the sum of products into a single binomial coefficient is not that hard to notice, due to the well-known Vandermonde convolution. One way is just to consider the mentioned interpretation.

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

its awsome, Like your previous competitions, this one also had a lot of mathematics!

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

div1A >> div1B

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

Rating roll back when ? I want to be expert in problem solving

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

just curious, who or what is Devyatkino, and how is it related to the 2067C problem?

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

Problem D was really interesting theory-wise, pretty cool for an interactive problem to actually be accessible for regular users rather than being 2300+ rated

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

A YouTube solution got leaked in the last 10 minutes of Problem E. I don't know much of Div. 1 but in Div. 2 more than 10 people in top 20 have been cheated having the same solution and it might get worse lower down in the standings. Some of the solutions are with comments and exactly same, I don't know how they escaped plagiarism but something needs to be done about these cheaters or else the fun of competitive programming will end soon.

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

In C, if n = 6, answer is actually 9, not 8, right?

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

Solved ABC and had some idea about D. The problems were interesting and the observations were not very obvious. Overall a nice contest.

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

There are a lot of cheaters at the top of the leaderboard(Div 2) Please look into it..

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

After regrading, my submission to Div. 1 A now says "Wrong answer on pretest 4." If my rating is going to be calculated based on this, this feels unfair, since it would not be hard for me to fix my solution to the problem, if I knew this was the verdict. Also, it seems that some people had the opposite problem, where their solutions failed in contest but were correct. I think the correct decision here is to void the contest.

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

"It is not difficult to understand that it is optimal to take the leftmost zero in the subsequence" for problem Div2 E why taking left most zero is optimal..?Can anyone explain in detail?

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

    You only need to consider the leftmost 0 for two reasons:

    1) You only need to check the condition until the zero you chose to keep in the subsequence. Everything after that will be valid (min = 0 and mx = 0), so you want to have the 0 as soon as possible.

    2) Checking until the index of the first zero is similar whichever the 0 you decided to choose, so based on the first point you want to check the smallest part possible.

    Consider for example the sequence 2 0 1 0 1, checking the first element is independant of the zero you chose to keep and if you decide to keep the second zero the condition fails on it (mn = 1, mex = 2)

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

    If the leftmost pattern does not get accepted then the other pattern will also get rejected as the same partition which rejects the leftmost pattern will also reject any other pattern.

    Ex : 4 3 3 2 1 0 1 3 4 0 6

    1) 4 3 3 2 1 0 1 3 4 6 -> this case pattern rejected for 4 3 and 3 2 1 0 1 3 4 6.

    2) 4 3 3 2 1 1 3 4 0 6 -> Similarly this pattern will also get rejected for 4 3 and 3 2 1 1 3 4 0 6.

    If leftmost patter fails then all pattern fails. So Check for leftmost pattern only.

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

sevlll777 Could you please tell the testcase where some of the rejudged solutions of Div 1.(A) have failed. Specifically testcase 37 on pretest 2.

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

Is there a way to solve the second problem using the frequency array?

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

    305680148

    Yes, of course here is how i solved it in the contest , do check it out bro. you take a frequency array and then check if it appears more than twice , redistribute the excess counts to the next number by increment operation. after that check if all frequencies are even then only it is possible.

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

In problem A of div1, if you use fast read in to read in, and your solution happens to be wrong, when you read -1, you'll get TLE on test 2 for not having end-of-line spaces and line breaks (at least in my tests, I think). In fact, for this reason, I kept thinking yesterday that it was cin/cout that was too slow and wasted almost 45 minutes. I don't know if this problem is present in other interaction problems, but I think it has a big impact on players who are experiencing this problem for the first time, and I think the interactive library should give the correct verdict on the procedure according to the rules. I hope this issue will be revised in the next time.

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

1E is a classic trick in CNOI.

I think 1E is easier than 1C in CNOI.

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

in C you said you cant explain it briefly! this is the contest for making people to get new ideas , to have fun , to learn new techniques, not for searching the random idea in your head which you cannot even explain briefly. Do you believe you explanation is worth it? CF is being a joke day by day just for problem setters like you who came here to show how cool are they not to set cool problems

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

    Have you read editorial through the end? It's not like I dont explain ideas, it is just a choice of words to justify (or motivate) idea of adding $$$10^x$$$ instead of $$$99.99$$$ in the operations, since it is easier to see how digits are affected in this case. I could just directly explain solution instead, but I believe explaining motivation behind some ideas is also important, and thats what Im trying to do usually, [side note:however I would agree that in D2E solution is not well-motivated, the thought of looking at zeros is pretty random, but] I believe D2C explained well, if not please tell me what is unclear...

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

In problem 2067D - Object Identification, why is one query insufficient in the second case (when $$$x_1,x_2,…,x_n$$$ is a permutation)?

Is there a case in which one query will give a response $$$ \gt =$$$ $$$n - 1$$$ and the other will not?

Can you provide a counter-example for the one-query approach? thank you :)

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

    something like

    3
    1 2 3
    2 3 2
    

    Path in graph theoretically can have length of $$$n-1$$$ if it goes through all vertices of the graph ($$$1 \to 2 \to 3$$$ in this case), and if $$$y_i = y_j$$$, Manhattan distance can be also equal to $$$n-1$$$.

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

Some thoughts on 2E / 1B. What if we consider the weighted version of this problem? I mean, let every $$$a_i$$$ have weight $$$w_i$$$, and now we need to find not the maximal possible length of a magical subsequence, but the maximal sum of weights in a magical subsequence.

Such version of this problem looks very curious for me. Now we can not just say that the subsequence without zeroes outperforms almost every other subsequence, and we need to go deeper. Seems i have a solution for this version, and it looks really nice (but, ofk, it also might be wrong :) ).

Did anyone have some thoughts like this?

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

Tutorial for 2067E — White Magic: "(this can be easily done in O(n), calculating prefix-min and suffix-mex is a well-known problem)".
I know how to calculate suffix-mex in O(nlogn), but I didn't know it can be calculated in O(n). What is the idea behind faster solution?

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

The interactor of div1 A seems to have some bugs.I got TLE on the sample but that's impossible.

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

Question about 2067F Bitwise Slides:
1) When x=pref(i-1): There are a total of 3 ways to arrive from (pref(i-1),pref(i-1),pref(i-1)).
2) When x is whatever: We can come from (x,x,pref(i-1)) to (x,x,pref(i)).
Aren't 2) when x=pref(i-1) and third way from 1) duplicates? How can we be sure that we aren't counting the same operation twice?

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

My implement for Div2 G. Maybe it's a little shorter and more pretty.306285879

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

1E can be solved with 1 log, i.e. $$$O((n+q)\log (a_i))$$$

Submission: 306294227

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

    And it's also easier to implement compared with the official segment tree + binary search approach.

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

    FYI (helped with AI translation)


    Solution

    Noticing that Operation 1 is only useful when two barrels contain the same weight of water (otherwise the presence of poison won't affect the result), and the barrels selected in Operation 2 must be confirmed poison-free.

    Initially, we must select two barrels with $$$k$$$ kg of water each and compare them. If poisoned, the process ends. We consider the case where their weights remain equal (i.e., no poison exists).

    At this point, the freely disposable water quantity is $$$2k$$$, denoted as $$$L$$$.
    All operations can be categorized into two types:

    1. Select $$$a_i \le L$$$, then update $$$L \leftarrow L + a_i$$$. (i.e., use $$$L$$$ to obtain a barrel with $$$a_i$$$ kg for comparison)
    2. Select $$$a_i + L \ge a_j$$$ (both $$$i$$$ and $$$j$$$ are unconfirmed), then update $$$L \leftarrow L + a_i + a_j$$$. (i.e., pour $$$a_j - a_i$$$ water into barrel $$$i$$$, then compare $$$i$$$ and $$$j$$$)

    Starting with $$$L = 0$$$, the initial process of finding two barrels with $$$k$$$ kg can be described using Operation 2. Therefore, we discard the first step and solve the problem starting from $$$L = 0$$$ with no confirmed barrels. If we can confirm $$$\ge n-1$$$ barrels as poison-free, output Yes (the last barrel can be determined by elimination).

    We accelerate this process using range doubling decomposition.
    Divide the value range into $$$O(\log a_i)$$$ blocks of $$$[2^k, 2^{k+1})$$$.
    A key property emerges: if any barrel in a block is confirmed poison-free, we can confirm the entire block.

    Proof:
    For a barrel $$$a_i$$$ in block $$$[2^k, 2^{k+1})$$$:

    1. If confirmed via Operation 1: $$$L' = L + a_i \ge 2a_i \ge 2^{k+1}$$$. Thus $$$L'$$$ exceeds all values in this block, allowing confirmation of all barrels via Operation 1.
    2. If confirmed via Operation 2: $$$L' = L + a_i + a_j \ge 2a_i \ge 2^{k+1}$$$. Same conclusion follows.

    For each block $$$[2^k, 2^{k+1})$$$, maintain two multiset to track:

    • Values within the block
    • Minimum differences between adjacent pairs in the block

    Traverse blocks from smallest to largest. If a block contains a confirmable barrel:

    1. Confirm all previous unconfirmed blocks (including this block)
    2. Add their total sum to $$$L$$$

    A block $$$S$$$ is confirmable if and only if:

    $$$ L \ge \displaystyle\min_{i \in S} a_i \quad \text{or} \quad L \ge \displaystyle\min_{\substack{i \in S\text{ and} \\ j \text{ is unconfirmed}}} |a_i - a_j| $$$

    The first condition is easy to check by maintaining the minimum value of each block.

    The second condition requires checking:

    • Differences between adjacent blocks' max/min values (however, if the previous block is confirmed poison-free, it shouldn't be considered, as it has been included in $$$L$$$)
    • Differences within the current block

    which can be done in $$$O(1)$$$.

    Thus, the time complexity is $$$O(n\log a_i)$$$. (because we only traverse each block once)

    Maintain the sum of confirmed blocks and count of confirmed barrels to determine the final answer.

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

    There is another solution with the same complexity

    Use a segment tree

    On position $$$i$$$ maintain the value $$$pref_i - i$$$ where $$$pref_i$$$ is the sum of elements of $$$a$$$ that you can have if you currently have value i. Now we can't get to the $$$x$$$ if min(0, x)$$$ \lt 0$$$.

    Now look at each pair $$$(a_{i-1}, a_i)$$$ (in sorted array). If you have access to the value $$$a_i - a_{i-1}$$$ then you have access to the value $$$a_i$$$, so you can do add(a[i]-a[i-1], a[i]). You can easily maintain this troughout queries using multiset.

    One more thing, you can see, for example, that this doesn't work for 2 2 4 11 100, because with 2 2 4 we think we can get 11 because $$$11-4=7 \leq 8$$$ but we can't use 4 twice.

    To avoid this do the following:

    If $$$2a_{i-1} \lt a_i$$$, do add(a[i], a[i])

    Else do add(a[i]-a[i-1], a[i]).

    305735628

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

The code for Problem F gives a sense of "the greatest truths are the simplest."

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

Solution for B

answer is either all positive numbers or all positive numbers and at max one fo the zero

we'll check weather we can take that zero or not by following method

Your code here...
void solve() {
  ll n;cin>>n;
  a.resize(n);
  ai(a,n);
  ll ans=0;

  for(auto x : a)if(x)ans++;
  set<ll> s;
  for(int i=1;i<=n+5;i++)s.insert(i);

  vll mn=a;
  for(auto &x : mn)if(x==0)x=9999999;
  for(int i=1;i<n;i++)mn[i]=min(mn[i-1],mn[i]);

  bool possible=0;
  ll pos=0;
  ll ans2=ans;
  for(ll i=n-1;i>=0;i--){
    if(a[i]==0){
        ll mex=*s.begin();
        if(i!=0 && mn[i]>=mex)possible=1;
        ans2=max(ans2,1+pos);
    }else{
        pos++;
        ll mex=*s.begin();
        if(a[i]<mex)possible=0;
    }
    if(s.find(a[i])!=s.end())s.erase((a[i]));
  }

  if(possible)ans++;
  ans=max(ans,ans2);
  cout<<ans<<"\n";


}


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

~~~~~~~~~~~~~~~~~~~~~ void solve() { // Your code here ll n;ci(n); vll a(n); fr(n) {ci(a[i]);} sort(all(a)); bool ok = true; ll i=0; ll num = a[0]; while(i<n){ if(a[i] == a[i+1]){ num++; i+=2; }else{ if(a[i+1]>num){ ok=false; break; } num++; i+=2; } }

if(ok) cout<<"Yes"<<endl;
else cout<<"No"<<endl;

} ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ why is it not working for b?

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

Can someone explain why answer can never exceed 7 in div2C