Proof_by_QED's blog

By Proof_by_QED, 14 months ago, In English
Rating Predictions

2065A - Skibidus and Amog'u

Problem Credits: chromate00
Analysis: macaquedev

Solution
Code
Rate The Problem!

2065B - Skibidus and Ohio

Problem Credits: cry
Analysis: macaquedev

Solution
Code
Rate The Problem!

2065C1 - Skibidus and Fanum Tax (easy version) and 2065C2 - Skibidus and Fanum Tax (hard version)

Problem Credits: larush
Analysis: macaquedev

Solution
Code
Rate The Problem! (C1)
Rate The Problem! (C2)

2065D - Skibidus and Sigma

Problem Credits: cry
Analysis: macaquedev

Solution
Code
Rate The Problem!

2065E - Skibidus and Rizz

Problem Credits: Proof_by_QED
Analysis: macaquedev

Solution
Code
Rate The Problem!

2065F - Skibidus and Slay

Problem Credits: chromate00
Analysis: chromate00

Solution 1
Solution 2 (Skibidi)
Code (Solution 1)
Code (Solution 2)
Rate The Problem!

2065G - Skibidus and Capping

Problem Credits: larush
Analysis: Proof_by_QED

Solution
Code
Rate The Problem!

2065H - Bro Thinks He's Him

Problem Credits: Proof_by_QED
Analysis: efishel

Solution
Code
Rate The Problem!
  • Vote: I like it
  • +38
  • Vote: I do not like it

| Write comment?
»
14 months ago, hide # |
 
Vote: I like it +8 Vote: I do not like it

First time I tried competing in Rust. Hopefully next time will go better. Thanks for the round!

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

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

»
14 months ago, hide # |
 
Vote: I like it +7 Vote: I do not like it

That was not Div4......

»
14 months ago, hide # |
 
Vote: I like it +67 Vote: I do not like it

I'm sure exactly zero people used the Auxillary Tree method to solve F.

»
14 months ago, hide # |
 
Vote: I like it -11 Vote: I do not like it

Problems really weren't newbie-friendly. The problems are excellent, but not for Div.4 contest. More like Div.3 — Div.2

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    This was my first ever competition other than the one i gave previously. First Div 4 competition. And the first and second problem were i mean pretty easy. The third problem was tough though i was able to solve it.

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Hope there are no more GPT or any AI during future contests.

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

pls tell me i'm not the only one that used LCA to AC F.

»
14 months ago, hide # |
Rev. 5  
Vote: I like it +27 Vote: I do not like it

Alternative solution for H:

Make a segment tree, and in each node, place the following things:

  • The length of the segment (call it $$$l$$$);

  • The number of subsequences with each start and end (call it $$$C_{i,j}$$$);

  • And the number of non-equal adjacent elements across all subsequences (call it $$$ans$$$).

We can find $$$ans$$$ in the following way: either the adjacent elements are both in the left, both in the right, or one's in the left and the other is on the right. So it's gonna be

$$$left_{ans} \cdot 2^{right_{len}} + right_{ans} \cdot 2^{left_{len}} + \sum_{0 \le i,j,k,l \le 1, j \neq k} left_{C_{i,j}} \cdot right_{C_{k,l}}$$$

.

This is what the code looks like: 305334877

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone please explain why two pointer does not work in Problem C2 after sorting array b?

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Because a is not sorted, so while you move the first pointer forward the second pointer may move backward, then forward, then backward and so on. The solution's time complexity will be no better than O(n^2).

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

could C1 also be solved using masks? 305285624 if yes, why doesn't this work ?

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I liked problem D. never used prefix sums like that before. Very interesting contest overall :D (A little too much brainrot for me tho). Also I was curious if using DFS/BFS is a good idea in problem F. It might be redundant, but if anyone solved with bfs/dfs, please share your solution.

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can anyone tell me where this solution for problem G might be going wrong
I believe, I did it similar to the approach given in editorial

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Can someone pls help with F problem. I have maintained a neighboring frequency map and just checking if frequency > 1 for some element.

https://mirror.codeforces.com/contest/2065/submission/305373353

»
14 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

2065D - Skibidus and Sigma Editorial

Sort each array in decreasing order. Sort the arrays themselves in terms of their sum, from largest sum to smallest Put together the final array Take the score This score is guaranteed to be maximal.

Bolded part is a mistake?

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    You cannot reorder an individual array. Read the statement carefully.

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Yes — DON'T sort the arrays in decreasing order! I misremembered the problem while writing the editorial! sorry!

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem G https://mirror.codeforces.com/contest/2065/submission/305402634 Can someone please tell me what i am doing wrong I am wrong answer on 4th case

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    I initially solved it by sorting, but your idea is also correct (proof 305556881). The only difference I see that could be wrong is you are using java.

    • »
      »
      »
      14 months ago, hide # ^ |
       
      Vote: I like it 0 Vote: I do not like it

      You are correct gives correct answer in c++ but why is that can you explain please

      • »
        »
        »
        »
        14 months ago, hide # ^ |
         
        Vote: I like it 0 Vote: I do not like it

        Bro, seems like I got it. It's not where I looked first:

        static void sieve(int n){
        ...
            for(int i=2;i*i<n;i++){
        
»
14 months ago, hide # |
 
Vote: I like it +3 Vote: I do not like it

Why my O(16 * n * logn) solution on H got tle :(

»
14 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

can somebody tell me at what test case my code might be failing 305361698

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    PLZ Somebody help me with this

    • »
      »
      »
      14 months ago, hide # ^ |
      Rev. 3  
      Vote: I like it 0 Vote: I do not like it

      Nevermind sorry, the advice I gave earlier is for C2.

      I looked through your code. I would try to make sure of two things:

      1. It seems like when you shift the one in front (d[i + 1] = 1), you then set the next one to always enter the first part of the for loop. In other words, in your code, I think once you flip one in front, it always flips the one in front regardless of whether or not it should. Always check, in your code, that every flip you do decreases or increases the number if it is expected to do that. It is a bit hard to tell what the d array is used for, it seems to be telling whether or not a bit is able to be flipped but is interacting with the ones in front, which haven't been checked yet?

      2. Make sure your code is not O(n^2) time complexity. I think your funci() and funi() functions are O(N), and if these run on every index, you might get a time limit problem because doing this on every index is O(n^2). I am not 100% sure of this.

      Sorry for the initial wrong example/

»
14 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

Question H's tutorial has faulty LaTeX in the "Solution" section near the bottom. In the last math's pseudocode, there's some oplus1 thing. I think it's just supposed to be s[j] XOR 1.

»
14 months ago, hide # |
 
Vote: I like it -8 Vote: I do not like it

CAN ANYONE EXPLAIN WHY THIS APPROACH TO c WAS WRONG?

https://mirror.codeforces.com/contest/2065/submission/305299896

  • »
    »
    14 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    we need something greater than prev( i.e, a[i-1]) in the ith position. two options: a[i] and someB-a[i].

    how do we find someB such that someB — a[i] >= a[i-1]? binary search for someB >= a[i-1] + a[i].

    However, your binary search looks for the incorrect equation.

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Does anyone tell me why my O(16 * n * logn) solution on H was TLE ? I read William Lin's solution and it may the same with mine

Here is my solution https://mirror.codeforces.com/contest/2065/submission/305249433

Here is William Lin's solution https://mirror.codeforces.com/contest/2065/submission/305272835

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I started from the end in C2 problem, and maximize the element but less then its next element, but i get wrong answer.

can anyone tell why this approach is different from the given approach

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

ARE RATINGS UPDATED?

»
14 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

forgive

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

hi everyone ! Could anyone please help me? Got some troubles on C2, it falls on a 2nd test, but ~7000th token. Cant figure out what the problem is:( 305525156

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it +1 Vote: I do not like it
    Spoiler
»
14 months ago, hide # |
Rev. 2  
Vote: I like it 0 Vote: I do not like it

My idea for H: Let $$$dp_0$$$ being the sum of all sequences ending at 0, $$$dp_1$$$ is defined the same way, $$$nums_0$$$ is the number of subsequences ending at 0 before position i, $$$nums_1$$$ defined the same way.

The brute force code looks like this:

               if (i)
               {
                   if (s[i - 1] - '0')
                       num1 += (1 << (i - 1));
                   else
                       num0 += (1 << (i - 1));
               }
               dp = {dp[0] + dp[1] + (num1 + 1) * (s[i] == '0'), dp[0] + dp[1] + (num0 + 1) * (s[i] == '1')};

So, how do we optimize this? Matrix multiplication is looking good here. Let's use matrix multiplication:

$$$\begin{pmatrix}dp_0 & dp_1 & nums_0 & nums_1 & 1\end{pmatrix}:=\begin{pmatrix}dp_0 & dp_1 & nums_0 & nums_1 & 1\end{pmatrix} \begin{pmatrix}1 & 1 & 0 & 0 & 0 \\ 1 & 1 & 0 & 0 & 0 \\ 0 & [s_i=1]&1&0&0\\ [s_i=0] & 0&0&1&0\\ [s_i=0]*(1+[s_{i-1}=1]*2^{i-1}) & [s_i=1]*(1+[s_{i-1}=0]*2^{i-1})&[s_{i-1}=0]*2^{i-1}&[s_{i-1}=1]*2^{i-1}&1\end{pmatrix}.$$$

The only thing left to do is to use a segment tree, which I implemented in 305304142.

  • »
    »
    11 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    My solution use 3x3 matrix.

    Let $$$n_0,n_1,S$$$ are the number of subsequences ending at 0 before position i, the number of subsequences ending at 1 before position i, the sum of f() before position i.

    when s[i] = '0':

    $$$n_0\to 2n_0+n_1+1,n_1\to n_1,n_0\to 2S+n_1+1$$$

    symmetrically, when s[i] = '1',

    $$$n_0\to n_0,n_1\to 2n_1+n_0+1,n_1\to 2S+n_0+1$$$

    One nice insight is homogenization (is that word?)

    Let $$$n_0'=2n_0+1,n_1'=2n_1+1,S'=2S+1$$$

    We have $$$(n_0',n_1',S')\to(2n_0'+n_1',n_1,2S'+n_1)$$$

    $$$M_0=\begin{bmatrix} 2 & 0 & 0 \\ 1 & 1 & 1 \\ 0 & 0 & 2 \end{bmatrix}$$$

    matrix for '1'

    $$$M_1=\begin{bmatrix} 1 & 1 & 1 \\ 0 & 2 & 0 \\ 0 & 0 & 2 \end{bmatrix}$$$

    We have

    $$$2\text{ans}+1=[1,1,1]\times \prod\limits_{i=1}^nM_{s[i]}\times [0,0,1]^T$$$

    Code 320437455 takes about 500ms

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Am I the only who is getting TLE in H after using segment trees effeciently(as far as i know) Can someone help me to optimize it ? 305573607

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    I have noticed a huge inefficiency in your code. You used vector<vector<ll>> as your node type, which stores a lot of useless data when the node is only 2x2. Replacing them with constant sized arrays make the code 30x faster (300ms vs 9s). Also, why is the seg array size $$$3n+10$$$ instead of $$$4n$$$? If you want to optimize on memory, consider an iterative segment tree instead :).

    305585533

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
  • »
    »
    14 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it +1 Vote: I do not like it
    Spoiler
»
14 months ago, hide # |
Rev. 2  
Vote: I like it +17 Vote: I do not like it

This was a great contest, which I thoroughly enjoyed virtualling with AG-88301, however I must say macaquedev's editorials are significantly lacking in their accuracy.

On line 1 of his editorial for D, he introduces a new term $$$c_2$$$, which appears from nowhere, and is clearly meant to be $$$b_3$$$...

In the editorial for E, he also says WLOG $$$n \gt m$$$ when the correct assumption to make is $$$n \ge m$$$, since you cannot assume they are not equal...

Can we have more proofreading of editorials as I find this frankly unacceptable that such simple mistakes were able to come through both macaquedev's editorals, and the seemingly non-rigourous proofreading by higher ups. I hope I will never see this kind of inaccuracy again.

User macaquedev is also reknowned for his use of the word "trivial", and I did not find it mentioned ONCE in this editorial set... This is frankly unacceptable behaviour and should be dealt with immediately!

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it 0 Vote: I do not like it

    Clearly someone stole his identity if the word trivial is not found anywhere in the text

  • »
    »
    14 months ago, hide # ^ |
    Rev. 2  
    Vote: I like it 0 Vote: I do not like it

    as a tester, i can say for all involved that we are sincerely sorry for this trivial oversight. in order to hopefully rectify this issue, we will be enforcing strict regulations to ensure that user macaquedev will be as trivial as possible. sorry for the inconvenience, and we hope that, going forward, reading macaquedev's work will be one of, if not, the trivialist of trivialities.

  • »
    »
    14 months ago, hide # ^ |
     
    Vote: I like it +3 Vote: I do not like it

    It's ironic that you complain about mistakes in my editorials when you can't spell "renowned".

»
14 months ago, hide # |
 
Vote: I like it -6 Vote: I do not like it

Nice Div. 4 contest. As a virtual contestant, I think the thoughts of these problems are fluid. And the difficulty setting of the questions is smooth.

»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In 2065C, what if we apply a similar logic from the back (i.e. start from the last index, try to maximize it, then for index i, pick the greatest value of a[i] that is <= a[i+1], then proceed to i-1 and keep doing this repeatedly). Will this not work? If not, why?

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

In solution of problem H, fix the sumI[s[j]\oplus1] += 2^(j-1) line.

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

for F can anyone tell what is the issue with this: https://mirror.codeforces.com/contest/2065/submission/321358047

»
11 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Easy solution to C2

this is one of the test cases that i was stuck 1 4 3 4 3 4 2 7 8 9

#include <bits/stdc++.h>
 
using namespace std;
 
int find(int a , int b){
    if(b < 2*a){
        return b - a;
    }else return a;
}
 
bool solve() {
    int n, m ; cin >> n >> m;
 
    vector<int>a(n), b(m);
 
    for(auto &p : a)cin >> p;
    for(auto &p : b)cin >> p;
 
    if(n == 1)return 1;
 
    sort(b.begin(), b.end());
    // int pre = -1;
    for(int i = 0; i < n; i++){
        if(i == 0){
            a[0] = find(a[0], b[0]);
        }else{
            int val = a[i-1] + a[i];
            auto it = lower_bound(b.begin(), b.end(), val);
            if(it!=b.end()){
                if(a[i] >= a[i-1] and a[i] < *it - a[i])continue;
                if(*it - a[i] >= a[i-1]) a[i] = *it - a[i];
                
            }
        }
        if(i > 0)
        if(a[i] < a[i-1])return 0;
    }
    return 1;
}
 
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int ttt = 1;
    cin >> ttt;
    while(ttt--) {
        if(solve())cout << "YES" << endl;
        else cout << "NO" << endl;
    }
}

this check is important "if(a[i] >= a[i-1] and a[i] < *it — a[i])continue;" if your elemet needs any change at all or not

»
10 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

For Question D Skibidus and Sigma, Where is it mentioned that we can even change the arrangement of the elements inside an array, from the question it seems like we can only decide which array comes at which place while maintaining the arrangement inside that array, but in the solution they have rearranged the elements inside the array too. Can anyone please explain.

»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

hack of this submission on problem C:

1
5 2
4 1 4 5 2
5 3
»
6 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Here is my much simpler solution for F 346635848. simply check if any value repeats in d <= 2 for any vertex, then it is majority value