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

Автор employed, история, 4 недели назад, По-английски

thanks to nifeshe for making my life easier with templates

2271A - Robot Odd Moves

Hints
Solution
Code
Rate The Problem!

2271B - MEX Game

Hints
Solution
Code
Rate The Problem!

2271C - XOR Problem

Hints
Solution
Code
Rate The Problem!

2271D - Target Infection

Hints
Solution
Code
Rate The Problem!

2271E - Array Emptying

Hints
Solution
Code
Rate The Problem!

2271F - Beautiful Pillers

Hints
Solution
Code
Rate The Problem!

2271G - Grid Filling

Solution Part1
Solution Part2
Rate The Problem!

2271H2 - Personal Issues (Hard Version)

Solution
Code
Rate The Problem!
  • Проголосовать: нравится
  • +173
  • Проголосовать: не нравится

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

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

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

Some people passed H2 by bitset.

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

damn C was annoying, I had to write a stresstester and print out a bunch of values to find it, Binary searrching inside poison blocks were fun in D! Nice round tbh <3

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

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

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

Brilliant contest.

Additionally, during contest I remembered the problem 2255D which involves binary searching the answer with time back-tracking trick while checking. It helps a lot for solving problem E.

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

God, he cooked the whole Jordanian community

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

I wasn't able to implement D, but it was a nice problem.

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

Really Nice approach for C . I just bruteforced and found a pattern . Couldnt prove entire thing tho

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

D could also be solved in O(n) using slope trick

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

    Can you explain in details the idea please? It's like a convex hull trick?

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

      Here is my attempt at explaining the idea:

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

    395356822 similar idea i think but my implementations is ass

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

Thanks for this contest, i have finally become a pupil

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

C can also be solved with gray codes, making this the first time I've actually used them in a contest

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

    Can you explain how please?

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

      Construct the gray code with all bits up to x (greatest power of 2 not exceeding n as in editorial). Then, repeat this list twice. You can use this list as the prefix xor array because it contains all values from 0 to 2^x-1 exactly twice. When you reconstruct the original array by taking the xor of adjacent elements, each element in the original array will have a single bit set which will not exceed n

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

      Given that you've established that all numbers from 0 to 2x — 1 must arise exactly twice in the prefix xor of the array (from the editorial).

      Gray codes define an encoding where adjacent numbers differ by a singular bit. To recover the original array; we take adjacent xors, the highest value any such value can take is x <= n.

      A gray code for [0, 2^n — 1] can be written using [0, 2^n — 1] itself in some order, which also holds cyclically, i.e, the last and the first differ by a bit too (helps with the occuring twice thingy)

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

    I couldn't give the contest but after the contest I did the same firstly I tried with prefix xors as 0,0,1,1.... which didn't work then did graycode of all of them. 0 1 0 2 0 1 0 4 0 1 0 2 0 1 0 8 0 1 0 2 0 1 0 4 0 1 0 2 0 1 0 , gives such a beautiful pattern , I could probably write a recursive solution ngl.

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

gray codes are a cute way to solve Div2C

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

When employed writes a contest. reference: https://youtu.be/Z9q-tzW_dzo?t=3644

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

Binary search over non-monotonous function in D is a beautiful trick!

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

Check out my submission for problem C, this is a recursive approach.

»
4 недели назад, скрыть # |
← Rev. 5  
Проголосовать: нравится +6 Проголосовать: не нравится

There is a much simpler (in the sence of implemenentation) O(n) solution to D.

The solution uses the sliding window technique. We start with $$$begin=end=n$$$

If the the last segemnt has size >= k, then $$$f(r_n-k+1)=k$$$. If not, we can move our $$$begin$$$ pointer left (and adding $$$holes+=l_{beg}-r_{beg-1}-1)$$$ until either $$$r_{end}-l_{beg}+1-holes$$$ >= k or $$$r_{end}-l_{beg}+1 \gt m$$$.

In the first case, let $$$filled=r_{end}-l_{beg}+1-holes$$$, then if $$$r-l+1-(filled-k) \leq m$$$ then $$$f(l_{beg}+filled-k)=f(l_{beg})-(filled-k)=filled-(filled-k)=k$$$, because 1. $$$[l_{beg},l_{beg}+filled-k]$$$ is all ones, because in the last step $$$filled_{old} \lt k$$$, so $$$r_{beg}-l_{beg}+1=filled-filled_{old} \gt filled-k$$$ and $$$[l_{beg}+m,l_{beg}+m+filled-k]$$$ is all zeros, because we know this it to the right of out $$$[beg,end]$$$ range ($$$r-l+1-(filled-k) \leq m$$$), and it's before the beggining of the next range, because either $$$end=n$$$ and there is no next range, or the next range was removed before at some $$$beg' \gt beg$$$. Then $$$r_{end+1}-l_{beg'}+1 \gt m$$$ and since it didn't terminate $$$r_{end+1}-l_{beg'}+1-holes_{beg'...end+1} \lt k$$$. If $$$holes_{beg'...end+1} \lt m-k$$$, then $$$r_{end+1}-l_{beg'}+1-(m-k) \lt k$$$ => $$$r_{end+1}-l_{beg'}+1 \lt m$$$ which is false, so $$$holes_{beg'...end+1} \gt m-k$$$ => $$$holes_{beg...end+1} \gt m-k$$$ (because $$$beg \lt beg'$$$) => $$$holes+l_{end+1}-r_{end}+1 \gt m-k$$$ => $$$l_{end+1} \gt m-k+r_{end}+1-holes=l_{beg}+filled-k+m$$$, so the start of the next range is greater then the end of the range used by $$$f(l_{end}+filled-k)$$$.

In the second case we move $$$end$$$ to the left and update $$$holes-=l_{end}-r_{end-1}-1$$$

If this procedure doesn't find any suitable $$$f(s)$$$'s, then none exitst (because this means that all $$$f(s) \lt k$$$)

My submission: 394022211

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

HARDforces

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

For $$$F$$$, is this correct? "First, notice that we can always make the array beautiful using at most 2operations, by setting $$$a_1=a_n=10^9$$$." If there is $$$10^9$$$ in the middle, how to do it?

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

A good starting point for problem C is to use Gray code
Just need to construct a Gray code sequence, and then reverse and copy it again

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

Although a lot less beautiful, E can be solved with a binary search on the amount of splits and a Fenwick tree for the check https://codeforces.me/contest/2271/submission/394037143

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

E was dayuuumm amazin', i thought of the binary search way, like if check(<=mid splits) is true, then check(<=mid+1 splits) is also true, so it is monotonic, but unable to figure out the "GREEDYNESS" of the check fn! :|

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

There's an alternate solution to problem B that I think some could find useful. The optimal strategy for Alice is to get as many lower-numbered cards as she can, and the optimal strategy for Bob is to copy Alice's moves (thus, also getting as many lower-numbered cards as she can). The reason why both players desire lower-numbered cards is because that is what changes the k-MEX the most.

Therefore, we can directly simulate how the game would play out. This runs in (I believe) O(n^2), which is slower than the tutorial, but passes all test cases nonetheless.

#include <bits/stdc++.h>
using namespace std;
int kMex(int k, vector<int> numbers, int maxNum){
    for(int i = 0; i<maxNum+1; i++){
        if(count(numbers.begin(), numbers.end(), i) < k){
            return i;
        }
    }
    return maxNum+1;
}
int main(){
    int tests;
    cin>>tests;
    while(tests--){
        int n, k;
        cin>>n>>k;
        int maxNum = 0;
        vector<int> nums(n);
        vector<int> alice;
        vector<int> bob;
        for(int i = 0; i<n; i++){
            cin>>nums[i];
            maxNum = max(maxNum, nums[i]);
        }
        sort(nums.begin(), nums.end());
        for(int i = 0; i<n; i++){
            if (i%2 == 0){
                alice.push_back(nums[i]);
            }
            else if(i%2 == 1){
                bob.push_back(nums[i]);
            }
        }
        if (kMex(k, alice, maxNum) != kMex(k, bob, maxNum)) cout<<"YES"<<endl;
        else cout<<"NO"<<endl;
    }
}
»
4 недели назад, скрыть # |
 
Проголосовать: нравится 0 Проголосовать: не нравится

For C problem, I did this simple idea imo

Idea: Use only powers of two and zeros. A subarray's XOR is 0 only if every bit in it is turned on and then off again. We arrange the bits so that to turn a bit off, you're forced to fire a another bit in between, which stays on. So no subarray with a nonzero element has XOR 0, and the only zero-XOR subarrays are single zeros (l = r with a[l] = 0).

Construction: Let k be the highest bit of n. Take length 2 ^ (k + 2) - 1. Put 1 in the middle, 2 in the middles of the halves, 4 in the middles of the quarters, and so on. Leftover cells are 0. For n = 2: 0 2 0 1 0 2 0.

In any subarray, the smallest bit appears exactly once, so the XOR is nonzero. Zeros are never adjacent.

Answer: beauty = (2 ^ (k + 2) - 1) - 2 ^ (k + 1) = 2 ^ (k + 1) - 1, which is optimal. There are only 2 ^ (k + 1) possible prefix XOR values, and each can appear at most twice.

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

Here is my code: recursion code for printing the pattern in C

void pattern(vector<int>& v, int n) {
    if (n == 0) {
        v.push_back(0);
        return;
    }
    pattern(v, n / 2);
    v.push_back(n);
int m=(int)v.size()-2;
for(int i=m;i>=0;i--)
 {
  v.push_back(v[i]);
 }
 return ;
}
»
4 недели назад, скрыть # |
 
Проголосовать: нравится +1 Проголосовать: не нравится

nifeshe can you add H1 and H2 pls, i guess Axial has already rested

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

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

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

couldn`t solve D during contest, but I upsolved it and it is now one of my favourite problems OAT! Nice round :)

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

I think the last part of the editorial's proof of problem E is incomplete. It shows that the greedy splits are legal in the original problem, but does not prove that the construction performs exactly $$$c$$$ splits.

For example, when $$$n=1,k=0,a=[1]$$$, the minimum feasible $$$c$$$ is $$$1$$$, but the greedy check performs $$$s=0$$$ splits.

Here is how we can complete the proof.

Let $$$c$$$ be the minimum feasible value. Suppose the greedy construction performs $$$s \lt c$$$ splits, leaving a sorted array $$$b_1\le \cdots\le b_{n+s}$$$. Since the check succeeds, we have

$$$b_j\le k+2c-s+j-1.$$$

By the minimality of $c$, the array cannot satisfy $$$b_j\le k+s+j-1$$$ for every $$$j$$$, otherwise $$$s$$$ splits would already suffice.

Let $$$i$$$ be the first index violating this inequality. Then

$$$b_i \gt k+s+i-1\ge k+s.$$$

Thus, we can legally append a split of $b_i$ after the previous $$$s$$$ splits.

Replace $$$b_i$$$ with two copies of $$$q=\lceil b_i/2\rceil$$$, obtaining an array $$$d$$$ (before sorting). We claim that

$$$d_j\le k+2c-s+j-2.$$$

Indeed:

For $j<i$: $$$d_j=b_j\le k+s+j-1\le k+2c-s+j-2$$$.

For $$$j=i$$$: $$$d_i=q\le \max(1,b_i-1)\le k+2c-s+i-2$$$, since $$$c \gt s$$$.

For $$$j=i+1$$$: $$$d_j=q\le b_i\le k+2c-s+i-1$$$.

For $$$j \gt i+1$$$: $$$d_j=b_{j-1}\le k+2c-s+j-2$$$.

Sorting $$$d$$$ preserves these inequalities because the right-hand sides are increasing.

Therefore, we can increase $$$s$$$ by $$$1$$$ while maintaining the invariant. Repeating this process until $$$s=c$$$, we obtain

$$$b_j\le k+c+j-1,$$$

which guarantees that all remaining elements can be erased after exactly $c$ splits.

The initial greedy splits are also legal in the original problem, since they occur only when $$$H \gt S\ge k+2c-s\ge k+s$$$.

Thus, a valid construction with exactly $$$c$$$ splits exists in the original problem, completing the proof.

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

C was simply brilliant coudnt solve without the help of editorial though but learned lot

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

Great Editorial!