ne_justlm's blog

By ne_justlm, 14 months ago, translation, In English

Thanks for participating in the most isekai NyaForces contest!

We honestly strived to make good tasks.

2072A - New World, New Me, New Array

Idea: ne_justlm

Tutorial
Solution
Rate the problem

2072B - Having Been a Treasurer in the Past, I Help Goblins Deceive

Idea: ne_justlm

Tutorial
Solution
Rate the problem

2072C - Creating Keys for StORages Has Become My Main Skill

Idea: ne_justlm, IceHydra

Tutorial
Solution
Rate the problem

2072D - For Wizards, the Exam Is Easy, but I Couldn't Handle It

Idea: ne_justlm

Tutorial
Solution
Rate the problem

2072E - Do You Love Your Hero and His Two-Hit Multi-Target Attacks?

Idea: ne_justlm

Tutorial
Solution
Rate the problem

2072F - Goodbye, Banker Life

Idea: itz_pabloo

Tutorial
Solution
Rate the problem

2072G - I've Been Flipping Numbers for 300 Years and Calculated the Sum

Idea: ne_justlm, IceHydra

Tutorial
Solution
Rate the problem
  • Vote: I like it
  • +67
  • Vote: I do not like it

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

F was so good!

Apart from the Pascal's triangle solution, You can do it by recursion and I learned that the self-similar repeating fractal pattern formed by F is called a Sierpinski's triangle!

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

nice

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

Thanks to the authors for a good round

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

constructive contest

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

For the F, if we use Lucas' Theorem, we can actually deduce that $$$\binom{n}{k}\mod 2$$$ is 1 only if $$$k$$$ in binary is a submask of $$$n$$$, in other words if $$$k$$$&$$$n$$$ equals $$$k$$$

With this there's an elegant two-line solution in $$$O(n)$$$:

int a,b;cin>>a>>b;a--;
for(int i = 0;i<=a;i++) cout << (int)((a&i)==i)*b << ' ';
»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

some how deepseek solved G on first try

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

ne_justlm In fact, the first part of the problem G is not $$$O(\sqrt{n} \log n)$$$. The reason is that the total time is equal to $$$\sum\limits_{i=2}^{\sqrt{n}} \frac{\ln n}{\ln i}$$$, and since the logarithmic integration yields a complexity of $$$\int\limits_{2}^\sqrt{n} \frac{1}{\ln x} dx=O(\frac{\sqrt n}{\ln n})$$$ for the latter part, the total complexity is $$$O(\sqrt{n})$$$

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

In the problem F, you said that we will build each the numbers in the n-th rows bit by bit, but why in the solution you just multiply it with the odd condition. I understand that when we have odd condition of power of 2 then the bit i-th at which Ki is set also must be set for the number, but do multiplication hold this property? Or how can I relate multiplication with xor property, thank.

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

    multiplication works because condition will be either $$$0$$$ or $$$1$$$, so multiplying by it is just the same as set all set bits from $$$k$$$ to $$$1$$$.

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

For the F , I tried to print out the triangle to find the pattern, and finally I found that they meet this pattern, can someone help prove it?

        for(int i =0;i < n;i++)
        {
            if((i|(n-1))==n-1)
                cout<<k<<' ';
            else
                cout<<0<<' ';
            cout<<endl;
        }
»
14 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Problem F: Not too different from the official solution, but I calculated the parity of binomials using the following formula:

$$$\begin{align*} \binom{n}{0} &= 1 \\ \binom{n}{r} &= \binom{n}{r-1} \cdot \frac{n - r + 1}{r} \end{align*}$$$

Then you can sequentially count the numbers of factor $$$2$$$ in the denominator and the numerator for each $$$r$$$.

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

    "count the numbers of factor 2 in the denominator and the numerator"

    what do you mean by this ?

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

      Let's say you can denote $$$\displaystyle \binom{n}{r}$$$ as a fraction $$$\displaystyle \frac{p}{q}$$$ (note this value is always an integer). Let's extract the factors of $$$2$$$ from $$$p$$$ and $$$q$$$:

      $$$\begin{align*} p &= 2^s \cdot p^\prime, \\ q &= 2^t \cdot q^\prime. \end{align*}$$$

      Where $$$s \ge t$$$ since $$$q$$$ divides $$$p$$$. Then the following holds:

      $$$\begin{align*} \frac{p}{q} \ \text{is even} \iff s \gt t. \end{align*}$$$

      Therefore, to find the parity of $$$\displaystyle \binom{n}{0}, \binom{n}{1}, \ldots, \binom{n}{n}$$$, you only need to count the number of factor $$$2$$$ s that appear in the denominators and the numerators in those values, instead of calculating those values in full. And this can be done sequentially, from $$$\displaystyle \binom{n}{0}$$$ to $$$\displaystyle \binom{n}{n}$$$, using the formula I wrote in the post above.

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

How tf did newbies and pupils know lucas theorem for F ???? Anyways F is a beautiful problem.

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

Seems like proof for E is not complete as "For k <= 446, the algorithm places no more than 43 sticks", how do we get this 43 sticks, do you proceed the same proof with upper bound is 446 instead of 10^5 and repeat for the next upper bound until reach 0? Do we have any formal proof, thank you!

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

Can anyone explain me why (n^2) solution worked in problem D? Because timeComplexity is (testcases*n*n) => (10^4 * 10^3 * 10^3) => 10^10 which is greater than 10^8, then why it not giving tle

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

    There is a condition on the input saying that sum of $$$n^2$$$ over all n in the testcase is bounded to $$$4*10^6$$$, so it is only $$$2*10^3 * 10^4 = 2*10^7$$$ operations, which fits the time limit.

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

      total complexity is $$$\mathcal{O}(\sum\limits_{i = 1}^{t} n_i^2)$$$ which is already bounded to $$$4 \cdot 10^6$$$. that would be the total number of operations

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

In the third case where $$$\log_p{n} \le \log_{\sqrt{n}}{n}$$$ , in the case where they are equal wouldn't the number of digits be $$$\log_p{n} + 1 = 3?$$$

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

kinda surprised this submission for E didnt TLE. i guess recursion is not so bad

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

I wasn't expecting D to be brute force of the nested loop type

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

Hi, I’ve implemented the following solution, and it fails on 2 test cases. I believe the logic is mostly fine, but I might be missing a specific edge case.

Could someone please help me understand what kind of edge case might be going wrong?

Especially this part seems suspicious:

if((or_value | (n — 1)) == x)

Here is my full code:

include <bits/stdc++.h>

using namespace std;

define ll long long

void solve(int d){ ll n , x , i = 0 , c = 0; cin >> n >> x; ll temp = x; vector binary(31 , -1); // complexity of this code is log₂(N) while(temp > 0){ binary[i] = temp % 2; temp /= 2; i++; } for(ll j = 0; j < i; j++){ if(binary[j] == 0 || binary[j] == -1) break; c++; } ll max_mex = (ll)pow(2 , c) — 1;

if(n == 1){
    cout << x << endl;
}
else if(n > max_mex){
    for(ll i = 0; i < max_mex + 1; i++){
        cout << i << " ";
    } 
    for(ll i = 0; i < n - max_mex - 1; i++){
        cout << x << " ";
    }
    cout << endl;
}
else if(n <= max_mex){
    ll or_value = 0;
    for(ll i = 0; i < n; i++){
        or_value = or_value | i;
        if(i == n - 1){
            if((or_value | (n - 1)) == x){
                cout << i << endl;
            } else {
                cout << x << endl; 
            }
        } else {
            cout << i << " ";
        }
    }
}

}

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

If anyone could help point out a counterexample or what I might be missing, that would be very helpful. Thanks in advance!

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

wow!!! , i came up with a new solution for question C, 323122376, can someone check out this and tell me if its worse or better than solution in tutorial

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

I think F can be solved by Lucas theory.Here my solution. ~~~~~ int n, k; cin >> n >> k; n -- ; for (int i = 0; i <= n; i ++ ) { cout << ((i & (n — i)) == 0 ? k : 0) << " \n"[i == n]; } ~~~~~

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

sooooo many math :(