eugenechka.boyko.2_0-0's blog

By eugenechka.boyko.2_0-0, 13 months ago, translation, In English

こんにちは, Codeforces!

Since our first round, we've learned a lot, and now we're excited to invite you to participate in Codeforces Round 1022 (Div. 2), which will be held at May/01/2025 17:35 (Moscow time). The round will feature 6 OR 7 full Leetcode implementation problems, where OR means the bitwise "we don't know" operation, and you'll have 2 hours to solve them. Some of the problems might be interactive — you can read more about interactive problems here.

The round will be rated for all participants with a rating below 2100, but everyone is welcome to participate out of competition as well.

All problems were authored and prepared by m3tr0, suprend, and me.

We would like to express our huge thanks to Akulyat for the fantastic coordination of the round and playing $$$\text{Tower Defense}$$$, as well as to all our testers:

And, of course, huge thanks to MikeMirzayanov for the すばらしい Codeforces and Polygon platforms, and You for participating!

UPD1: Score distribution: $$$500-1250-1500-2250-2750-3250$$$

UPD2: Congratulations to all the fighters of trees and towers! The final mousing:

All participants:

  1. peti1234
  2. BurnedChicken
  3. potato167
  4. propane
  5. jiangly

Moused only:

  1. 2018LZY
  2. ft2007
  3. pzjQWQ
  4. cooluo
  5. under1oop

UPD3: Editorial is here!

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

Isn't this quite late for the announcement to come out

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

what's the score distribution?

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

i have engineering graphic exam the next day of this round but i am from a warrior race

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

As a spectator excited to see how many of our talented newbies AK the contest

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

    As we know, many newbies are talented in using LLMs.

    It is well known that many newbies are talented in the use of LLMs.(As a steady newbie, it's clear that I'm not one of them)

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

image

hope to become CM

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

The subarashi in Japanese takes you to a random subarashi video. crazy man

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

May the force be with you to rock on..

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

All the best everybody :)

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

what about scores?

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

As a participant, I hope to solve two or three problems in this contest.

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

I hope it is not a speed round.

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

Hope to be Pupil!

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

Hoping for colour change delta

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

6 OR 7 problems, where OR means the bitwise "we don't know" operation

Should I be scared?

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

I'll get orange now

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

Subarashiiiiii!!!! (¬‿¬)(¬‿¬)(¬‿¬)

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

Happy May Day!

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

The OR in the announcement is the bitwise AND operation

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

As a participant, there will be a lot of blogs about cheaters right after the contest.

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

    It's great to see so many people taking it upon themselves to maintain the codeforces community environment.

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

    just like after every contest lol, but actually it seems like gpt is very bad with solving them

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

    I am so unlucky that I commented there was going to be a ton of blogs about cheating (like literally every contest in the past two months) and there was none. Maybe I should comment this under every contest I participate to avoid cheaters. If I was born 2000 years ago I would’ve bet my life saving on Golias for 1.1 odd ;(

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

hoping for the first time in top 4k in div2 !

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

Scores? A: 500 B: 1250 -_- Used to seeing A 750 and B 1k guess now that’s the new norm.

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

Cherry_blossom_ this person used ai in the last educational round and most probably is using ai now

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

hhh, I have used too many time on problem B. It is a good problem!

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

me reading problem A .. is this div1 A

me reading problem B .. is this div1 B

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

I had 30+ seconds remaining, yet the submit button was not clicking. Too bad codeforces.

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

When is editorial coming out

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

What's up with these shitty difficulty distributions lately? D is way too hard for its position.

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

    My solution just barely fit in the time limit, I basically just used binary search but we'll see if that is correct and fast enough

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

    I think main observation was window of size K will repeat in both A and B but I was not able to completely solve it :(

    I tried binary searching where the pattern breaks but couldn't handle all cases.

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

      I generated a vector of all possible indices i within [k, n-k+1] where a[i] and b[i] differ. a[i] assuming a is max length (n-k), and b[i] assuming b is max length (n-k).

      Then I did binsearch on that vector. If the middle ends up being one or more indices where a[i] = b[i], then -1.

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

        oh cool.. I tried to binary search on the first element which was not matching ... I guess your solution is better but not sure if it will overflow the number of queries

        I did this calculation ... logN ~= 20 and I can't make 20 * k ( ie 20 * 50 ) queries

        but generally protests have one such case which breaks the time limit.. so it can go through.. best wishes

        • »
          »
          »
          »
          »
          13 months ago, hide # ^ |
          Rev. 2  
          Vote: I like it +6 Vote: I do not like it

          constructing a and b is k queries each (so at most 100). then binsearch on n (1e6) is at most 20, so should comfortably be enough queries.

          the bigger problem is that my solution passed pretest in 2.937s, time limit is 3s so we'll see

          edit: passed :D

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

    D felt quite normal difficulty to me, I solved it pretty quickly

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

Hi, may someone please explain me D or give me a hint on why I might get TLE?

My submission is: 318015724

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

At first sight: C<D

In fact: C<<<<<<D

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

Your explaining pictures are excellent! I like it very much! How did you make it?

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

B,C=C,B

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

for the question 2 :

how the answer is 8 or 5 0 can someone elaborate ??

because for length 5 the minimum sum can be 4 1 1 1 1 0

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

Worst round I have joined yet

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

    Why? A problem seems to be some observation or trick, I couldn’t get. But overall A, B, C, seemed as always, no?

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

      Wayy too many adhoc.. For A you just have to kinda guess it, for B you just have to if else and if else. I guess C is alright but then it doesnt use any classical techniques so really it should be at B .. Then it is immediately followed by D which is diabolical

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

personally, I felt like the difficulty order was A > B > C.

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

    A: 1 + (maximum possible sum) /2 ... However, I don't have a formal proof for this.

    B: lots of casework and handling them gracefully

    C: simple observation => calculate total no of local maxima

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

casework in B makes it much tougher compared to C, C is just simple observation and sets

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

What is the question of B, inexplicable!!!!

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

am i dumb or was c more doable than b?

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

Did the authors mistakenly perform B^=C, C^=B, B^=C?

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

Can anyone please help me with this code for problem C. It passed the first pretest but was failing again and again in second pretest. Any help would be appreciated.

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class ProblemC {
    public static class FastReader {
        private BufferedReader buffer;
        private StringTokenizer tokenizer;

        public FastReader() {
            this.buffer = new BufferedReader(new InputStreamReader(System.in));
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(buffer.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() { return Integer.parseInt(next()); }
        public long nextLong() { return Long.parseLong(next()); }
    }

    public static void main(String[] args) {
        FastReader fast = new FastReader();
        final StringBuilder output = new StringBuilder();
        int t = fast.nextInt();
        while(t-- > 0) {
            final int n = fast.nextInt();
            long nums[] = new long[n];
            for(int i = 0; i < n; i++)
                nums[i] = fast.nextLong();
            output.append(solve(n, nums)).append("\n");
        }
        System.out.print(output);
    }

    public static int solve(final int n, long nums[]) {
        Map<Long, List<Integer>> indexMap = new HashMap<>();
        boolean marked[] = new boolean[n];
        for(int i = 0; i < n; i++) {        // Creating a map to store the indices of similar elements
            if(!indexMap.containsKey(nums[i]))
                indexMap.put(nums[i], new ArrayList<>());
            indexMap.get(nums[i]).add(i);
        }
        Arrays.sort(nums);      // Sort the weights array
        int index = n-1, count = 0;     // Start from descending order
        while(index >= 0) {
            for(int marker : indexMap.get(nums[index])) {
                // For each index of the same value
                if(!isMarked(marked, marker, n))     // check whether it can be marked
                    count++;            // If it cannot be marked create a clone there and mark it
                marked[marker] = true;
            }
            index -= indexMap.get(nums[index]).size();      // Subtract the group size to get to the next group
        }
        return count;
    }

    public static boolean isMarked(boolean marked[], int index, int n) {
        if(index > 0 && marked[index-1])        // Left check
            return true;
        else if(index < n-1 && marked[index+1])     // Right check
            return true;
        return false;       // If both check fails then it cannot be marked currently
    }
}
»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

how to solve D, E ?

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

D seems like binary search problem. I may be wrong.

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

The gap between C and D is too big!

I spend on A,B,C for only 30 min, but it took an hour and a half on solving D, and there was still no gain from D.

Is this a penalty sitting?

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

took too long to realize A. and got cooked on B.

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

I hope the System tests accounts for O(n) sols in D.

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

In problem D, does there exist a test case that we can find the lengths of arrays A and B in more than 250 queries?

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

Where is the editorial?

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

why not swap pB & pC, and it's the worst pB I experienced.

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

In my humble opinion, B was really not fun. I couldn't find a better approach than to enumerate edge cases, which isn't much interesting imo.

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

who spent time actually figuring out problem A.. I just guessed it will always be even :( very sad.

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

    The same for me. I just noted that it always should be even -> got max value and added zero sum. And it just works

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

      yeah it was horrible..

      I just guessed and counted odd values as well first.. but then saw the answer was near half of what I was getting and then guessed it will always be even .. lol .. shame on me.

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

Edit: Nvm I outputted x+1 instead of x.

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

Overall Good contest I enjoyed A, B and C.

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

How to solve B? C was easier than B imo.

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

    It's too many conditions and too many if-elses.Need to carefully think of what if n is 1,2,other;and what if x is 0,1,other.

    Here's my code.https://mirror.codeforces.com/contest/2108/submission/317970208

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

    B was just greedy.. look at the binary representation of x and notice that all the set bits of X other than the 0th bit should come only once in answer if we want to minimize the sum and rest all numbers can be one.. Of course there is an edge case which was mentioned in sample cases as well 317990225 you can understand it from here.. For some reason i messed up C , i feel dumb right now, could have been a great contest for me but nonetheless will see next time.. Can you tell your approach for Problem C?

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

I know I failed in solving problem E, but knowing the solution of this seems to be a big help.

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

casework problem like B, can hell your whole contest xD

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

this round was harder than usual

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

The statement of D is so poorly written. It took me 20 minutes to understand that every $$$k$$$ consecutive elements of $$$A$$$ and $$$B$$$ are permutations of $$$1$$$ to $$$k$$$.

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

What's wrong with my C 317997945

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

how did you guys solved c ??

void solve()
{
    int n;
    cin>>n;
    vi a(n);
    for(ll&i:a)
    cin>>i;
    vii pos;
    for(int i=0;i<n;i++)
    {
        pos.push_back({a[i],i});
    }
    sort(pos.begin(),pos.end());
    vi temp;
    for(auto it:pos)
    {
        temp.push_back(it.second);
    }
    multiset<int>clone;
    int cnt=0;
    while(!temp.empty())
    {
        int x=temp.back();
        temp.pop_back();
        if(clone.count(x+1)||clone.count(x-1))
        {
            clone.insert(x);
            continue;
        }
        clone.insert(x);
        cnt++;
    }
    cout<<cnt<<'\n';
}

this is mine please tell me where it is going wrong

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

Struggled for A more than B,C. Overall its a good contest, atleast for me w.r.t A,B,C

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

Finally a contest where accepted solutions for A, B and C seems human rather than LLMs

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

As a participant I Realllly enjoy in that constest

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

What was tc 4 in D, kept getting Wrong answer on it T_T

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

casework for B is like sooo worst

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

Overall good contest, was able to solve A,B,C.

I was trying to solve D using binary search, and was not able to implement it during the contest, will upsolve. Anyone who has done it using Binary Search???

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

EdgecaseForces

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

what the hell is the 7th test case for D?

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

E was easier than B imo

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

Rating is going to take a huge hit after this round. I can usually solve atleast 1-2 questions in div2. Could not solve any this time :(

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

    If you haven't submitted anything, then your ratings are unaffected.

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

    I get it, this A was based on observations about the possible values of the sum, which aren't that straightforward at all. B felt around the same difficulty as C. B was kinda heavy on casework, and C was even more observation-based with an easy implementation.

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

Wasn't there supposed to be a contest on saturday(3rd of may)?

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

    yes there will be another contest on the 3rd

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

      Well..it doesnt show up and i remember it was from those guys who made round 1021 which got a lot of hate cause of poor statements hopefully they dont back down on us:)

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

very good Div1 guys

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

can someone tell why my solution for c is failing ? 318011548

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

Amazing problem D ! thanks for the authors for that but I which C and B was more interesting.

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

Worthless idiot like me deserve to be butchered like a pig. I practice and solve 2200+ rated problems without editorial and get 2000 performance in virtual, then reality says fuck you and I don't solve Div2B. Every time I do virtual it's CM performance but real contest I get 1600? Why? I love solving problem but every time I do contest I get severe depression the whole day after, maybe best I quit CP before I develop some mental disease.

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

    dont be so hard on yourself.. keep practicing .. it will take some time.. but it will improve..

    anyway if you are able to solve 2200 problem I should not give you advice... lol

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

    this B was just a bunch of casework and the contest overall was bad, did you try solving C or D after not being able to solve B? you probably got really panicked after not being able to instasolve B and then you ruined the entire contest. i couldnt instasolve A this contest, and i coyuld have panicked as well, but you really just have to keep calm and relax in those situations. and in the end after taking 10 minutes to solve A, i had a CM performance, because i kept calm and read B before returning to A with a clear mind. all of this will come with experience and you shouldnt beat yourself up after a bad contest. especially since you really have nothing to lose in these contests except virtual points. making mistakes is important in these online contests, so when you do irl contests you can avoid them

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

    c was trivial compared to b...

    so yeah b is a really ugly outlier (stress test forces)

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

pretty bad contest, speedforces with ABC, and then a really hard D. i find D really cool even though i didnt solve it, and i think i will enjoy upsolving a lot, but the overall balance of the contest is terrible(even though this is my best performance ever in any contest and i think i will even reach expert lmao)

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

When is editorial coming out??

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

can someone help me about how can i try and run the first testcase of interactive types problem?

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

    I don't really think there is a way to run interactive testcases because the result is always hidden by the jury.

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

    are you asking how to test interactive problems on your own?

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

    You can

    • Just interact with the program you wrote manually.
    • Pretend that you’re doing OI-style (write everything as functions) so you can write a simple grader.
    • (How I do it usually) Just submit and pray. WA Test 1 doesn’t affect scores.
»
13 months ago, hide # |
 
Vote: I like it +21 Vote: I do not like it

Image

Tags for A are trying to say something

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

banger round, one of my favs thus far <3 thanks to the writers and testers orz

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

Trolled myself in C

only after finishing the buggy implementation did i notice you could move any clone, not just the newest one

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

A -> observation, Maths B -> Bit Manipulation. Greedy

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

how do you solve E? is it just look at the diameter and remove a leaf not on diameter, otherwise remove a leaf on diameter? or is there more lol

also ty contest creators, not bad round + i promoteforces :]

  • »
    »
    13 months ago, hide # ^ |
    Rev. 4  
    Vote: I like it +16 Vote: I do not like it

    Consider the tree, rooted from it's centroid, in this case lca of each pair with same color is root of the tree and we should merge the vertex $$$v$$$ with the minimum $$$h[v] + sz[v]$$$, where $$$h[v]$$$ is the number of edges from $$$v$$$ to root and $$$sz[v]$$$ is size of the subtree with root $$$v$$$.

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

For $$$D$$$ 121/122 queries are enough

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

Ordering of B and C should be swaped .... . Problem B was a little nightmare ..........

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

Excuse me, why do I get a Memory Limit Exceeded (MLE) error in this C programming problem? 318031123

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

    since you are using priority queue, you probably have a logic error that results in you pushing extraneous nodes (perhaps infinitely) into the priority queue

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

D was a very fun problem, probably one of my favorites!

Solution for D
»
13 months ago, hide # |
Rev. 3  
Vote: I like it 0 Vote: I do not like it

S

»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it
#include <bits/stdc++.h>
using namespace std;

#ifdef LOCAL
#include "debug.h"
#else
#define dbg(...)
#endif

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    
    int Q; cin >> Q;
    do [&](){
        int n;    cin >> n;
        
        vector<pair<int, int>> a(n);
        for (int i = 0; i < n; ++i) {
            cin >> a[i].first;
            a[i].second = i;
        }
        sort(a.begin(), a.end(), greater<>());

        dbg(a);

        set<int> S;
        int ans = 0;
        for (int i = 0; i < n; ++i) {
            if (!S.contains(a[i].second-1) and !S.contains(a[i].second+1)) ans++;
            S.insert(a[i].second);
        }
        cout << ans << "\n";
    }(); while(--Q);

    return 0;
}

Can you please tell why this algorithm failed on C?

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

    The code below works (318056161). I just removed non-unique consecutive elements.

    Code


    Your code fails on this test case:

    Test

    Basically it marks first $$$5$$$ (and increase the answer). Then it goes to the last $$$4$$$ and as the middle $$$4$$$ is not marked it increases the answer again. So it gives the answer $$$2$$$, instead of $$$1$$$. We go $$$5 \,\rightarrow\, 4 \,\rightarrow\, 4$$$.

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

Is there a more straightforward observation to get the answer for A? I had to do the following:

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

    When I was solving, I just guessed the answer. After the contest I came up with this:

    1. The minimal value is when $$$p_i = i$$$ and that's $$$0$$$.
    2. Let we have an array $$$c$$$ that has all elements from $$$1$$$ to $$$n$$$ twice ans sorted, like $$$ [1, \, 1, \, 2, \, 2,\, \dots, \, n,\, n ]$$$. When we open absolute value parentheses, there will be $$$n$$$ and $$$n$$$ values with plus and minus. The best is to have last $$$n$$$ with pluses and other with minuses. That's possible with pairing $$$c_i$$$ with $$$c_{2n + 1 - i}$$$ for all $$$1 \leq i \leq n$$$ (so $$$[1, n], \, [n, 1], \, \dots$$$).
    3. Let's take any permutation. When we swap two consecutive elements we increase the value by either of following $$$[-2,\, 0,\, 2]$$$. So going from $$$p_i = i$$$ to $$$p_i = n + 1 - i$$$ by swapping two consecutive will lead to visiting all values from $$$0$$$ to max. As we can't have odd values (because we increase by even value each time) the answer is $$$\frac{\text{max}}{2} + 1$$$.
»
13 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

Great contest. Thanks!

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

I read the Problem C for an hour.I thought the clone means another copy of a button. What can I say.

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