myst-6's blog

By myst-6, history, 18 months ago, In English

Hello Codeforces! Me and yud08 are excited to invite you to take part in Codeforces Round 982 (Div. 2), which starts on Oct/26/2024 17:35 (Moscow time). You will be given 5 problems and 2 hours to solve them. Two problems are divided into two subtasks.

This round will be rated for all participants whose rating is strictly below 2100.

The problems were authored by me and yud08, and prepared by me.

We would like to thank:

We hope you enjoy the problems!

Score Distribution: $$$500 - 1000 - 1250 - (1250 + 1000) - (2000 + 1000)$$$

We actually wanted to continue the trend of posting photos of contest writers, but we could only find one photo containing both of us, which was a group photo that we took with some other UK informatics people! (I'm the one in the back of the picture who is wearing the MHC T-shirt and yud08 is the one whose head is popping out from the left side of the photo.)

20240921-153321

UPD1: Congratulations to the winners of the contests:

Div 1:

  1. jiangly
  2. neal
  3. SSerxhs
  4. A_G
  5. kotatsugame

Div 2:

  1. nathan_higgs
  2. puru-puru-pururin
  3. Nonoze
  4. Hong_Meiling
  5. Nika_Tamliani

Also, first solves! (if any of these are wrong please let me know)

UPD2: Editorial is available here

  • Vote: I like it
  • +492
  • Vote: I do not like it

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

As a tester, this is my first "as a tester" comment.

»
18 months ago, hide # |
 
Vote: I like it +92 Vote: I do not like it

Since we all know real Codeforces rating is actually determined by rating * contribution, as a writer, give me contribution.

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

As a tester, the contest is very good and I like all the problems!

Also, orz myst-6

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

as a tester, i swear on skippity problem F can be solved by binary searching a segment tree and morphing the result into a dsu before finally getting the answer using a mixture of crt and fft (alternatively you can use a persistent 1729-dimensional convex hull trick on a sparse segment tree)

Also, orz myst-6

»
18 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

As a tester, do not miss the contest.

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

Love the photo! Who are the other mysterious coders in it? One of them has a blank screen. We need to know :)

»
18 months ago, hide # |
 
Vote: I like it +40 Vote: I do not like it

As a tester, just put the contribution in the comment bro

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

Another quick chance to re-perform after all these greedy pains and hacks on map... Hope to reach pupil again this time

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

Last year I made the same question and still don't know why to make a contest on Ieeextreme day T~T Ik maybe it's not on clist but most of coders know about ieeextreme and its date. Anyway, Thanks authors for a new round ^-^

»
18 months ago, hide # |
 
Vote: I like it +23 Vote: I do not like it

I am the camera

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

Whats (1250 + 1000). Can someone explain?

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

    It's a problem with a subtask, subtask of a problem means it will be a similar problem but with harder constant or condition.

    Another way to see it is 2250 problem being splited out into (1250 + 1000) for easier approach. Which aimed at weaker contestant to have a chance at solving (like me, the lower rating part).

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

LongTrainDiv2

»
18 months ago, hide # |
 
Vote: I like it +17 Vote: I do not like it

As a tester, I love the problems! \(^▽^)/

Also, orz myst-6

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

wtf these guys look too chad to be studying cs

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

As a tester, I can confirm that problems have statements

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

clashes with lc biweekly

should I give cf div 2 or leetcode biweekly?

»
18 months ago, hide # |
 
Vote: I like it +24 Vote: I do not like it

this is a really good practice of keeping the photos of people preparing the contest, it gives good vibes + i personally feel that yes in today's AI world still there is human interaction which makes me happy.

»
18 months ago, hide # |
 
Vote: I like it +59 Vote: I do not like it

As a tester, I've purchased this contest for kids' enjoyment.

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

First CF after AFO.

CSP rp++ (CSP: a very important contest for Chinese OIers, just ended 30min ago)

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

Guys you giving LeetCode Biweekly or, Codeforces Div 2? Imma confused :(

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

    Ofcourse Codeforces, Codeforces is like a lover, who gives you a lot of emotional pain, but still you want to be with her.

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

myst-6 fasrsi baladi?

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

Is there gonna be a hacking phase?

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

Good Index.

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

hope i become specialist after this round :)

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

why is contest registration closed before the start?

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

Oh, speedforces today!

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

Any hints for E1? I feel like the nimber for each pile should only be revolving around $$$\text{popcnt}(x_i)$$$, but I hardly came up with anything...

Wasting 40min thinking about E1 while I could have been coding D2 should be one of the worst tactical decisions I've ever made XD

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

so close to solve C but failed...

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

Oh! Because I wasn't familiar with discretization, I lost a lot of ratings in this round.꒰╬•᷅д•᷄╬꒱

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

How do you solve C ? I couldn't solve it no matter what

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

Alright, so how to count the number of ways to achieve the result in D2? Struggled for an hour and still didn't get past TL8 (all other ideas just WA-ed).

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

    Take the DP table used to solve D1 (one with states [elements removed][value of $$$k$$$]). In this table, I'm assuming you found the minimal cost for each state by doing the minimum of costs required when increasing $$$k$$$ by 1, and when removing a prefix, where removing the largest one doesn't hurt.

    When increasing $$$k$$$ by 1, the number of optimal options assuming you do that is obviously just the number of optimal options for the state with $$$k$$$ greater by $$$1$$$.

    However, when removing a prefix, it's possible that removing a smaller prefix would also lead to an optimal solution. However, what you can note is that as the number of removed elements increases, the minimal costs required to finish are non-increasing. So, what you can do is first find the optimal cost, then use binary search to find the smallest prefix you can remove if you want to achieve that cost, and then calculate the sum of numbers of options for each prefix between the largest one with this cost and the smallest one with this cost (doable with suffix sums).

    Now, just compare the minimal costs obtained by increasing $$$k$$$ and by removing a prefix, if they're unequal, take the smaller one and the number of options for that operations, and if they're equal, take that cost and the sum of numbers of options for both of these operations.

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

How do you do C? I tried a graph solution but it was too slow.

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

i got so confused on B, worst performance in a while. i found C pretty cool, and D1 seems doable, but i just wasted too much time on B. nice round

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

hints for D1??

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

How to solve A? Really do not understand why my solution was wrong.

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

Awesome B. Cost me 1 hrs + 3 WAs. That B is fucking hard, C is much easier. I think D1 is easier than B, but I have no enough time to solve it.

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

    Was your solution $$$O(n^2)$$$ (which passes, and IMO isn't hard to do), or something better (which probably is much harder than C)?

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

      My sol is O(n^2). But I just can't get the idea during most of the time of the contest.

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

wtf was b's solution? I know im sleep deprived, but im felling dumb af

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

    Say x is at index i then all the elements after index should be smaller than x. And for all the elements before index i, we only care about the elements before the maximum element upto index i, we will need to remove all those.

    288132226

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

      idk if I understand it well, but thats basicly what I did I kept searching for the max element on the vector, then I removed all the elements from the right of it

      Then i searched again for the max element up to index of the last max and on and on

      Then my answer was the number of max elements — the max element between the max elements it passed only test 1

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

        alright so lets take an example

        3 6 9 4 2 5 2

        say i am checking for index, i = 5 (1 based indexing), so the idea is to make both the right side (i>5) and left side (i<5) suitable but i handled that sepertaely

        for the right side, so the no of elements greater a[j] > a[i] such that j>i is simply 1, i.e., only 5( for j =6)

        for the left side, the ideal way is to remove all the elements before the maximum upto i = 5. so the maximum upto i = 5 is 9 and no of elements before it is 2.

        so total = 1 + 2 = 3, so if i had to make i = 5 as sort of the "center" of my arrangement then i need to remove 3 elemnts

        Now i will run this algo for all i from 0 to n and keep on taking the min for it

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

    Since n is small, you can count for every index i, number of a[j]>a[i] such that j>i by brute force.

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

    brute force the following for each i and pick the minimum:

    i + # elements a[j] (j > i) such that a[j] > a[i]

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

I printed lots of pairs $$$(n,k)$$$ on problem E1 and try to guess answer, it takes me 2 hours, just for 1000 points?

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

As a newbie, I am just never able to solve B (crying emojis)

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

    Don't cry for things out of control, you can start with some easier problems or exercise thinking skills. It's unnecessary to worry about how many problems you have solved but how many skills you have learnt.

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

Problems A, B and C were pretty good, but D1 is too easy. It is a really standard DP problem. Also speedforces.

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

All dp? Solved B, C, D1 with dp.

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

How to solve E1? My code is timing out when computing the SG function. Can someone help me?

#include <bits/stdc++.h>
 
#define int long long
 
constexpr int N = 1e5 + 6;
 
int mex(std::set<int> &s) {
  int m = 0;
  while (s.find(m) != s.end()) ++m;
  return m;
}
 
std::map<std::pair<int, int>, int> mp;
 
int SG(int x, int a) {
  if (x == 0) return 0;
  if (a >= x) return __builtin_popcount(x);
  if (mp.count({x, a})) return mp[{x, a}];
  std::set<int> s;
  int d = x;
  while (d > 0) {
    if (d <= a) {
        s.insert(SG(x - d, a));
    }
    d = (d - 1) & x;
  }
  return mp[{x, a}] = mex(s);
}
 
void solve() {
  int n;
  std::cin >> n;
  std::vector<int> a(n + 1, 0), x(n + 1, 0);
  for (int i = 1; i <= n; ++i) std::cin >> a[i];
  for (int i = 1; i <= n; ++i) std::cin >> x[i];
  int ans = 0;
  for (int i = 1; i <= n; ++i) ans ^= SG(x[i], a[i]);
  std::cout << (ans ? "Alice" : "Bob") << "\n";
}
 
int32_t main() {
  std::ios::sync_with_stdio(0);
  std::cin.tie(0), std::cout.tie(0);
 
  int t;
  std::cin >> t;
  // t = 1;
 
  while (t--) {
    solve();
  }
 
  return 0;
}
»
18 months ago, hide # |
 
Vote: I like it 0 Vote: I do not like it

I don't understand why B's constraints are low when a non-n^2 solution is not hard to do and fits a div2 B. (Yes, I am annoyed that I didn't look at the constraints, which is totally my fault).

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

    I think that a better solution than $$$O(n^2)$$$ is a bit too hard for div2B (some people are already saying it was too hard). Maybe having an easy version where $$$O(n^2)$$$ passes and a hard version where it doesn't would work better?

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

    What is the 'fits a div2 B' solution? I see you used pbds to find the order and that is definitely not D2B level. It's more like a D2D.

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

      Well, finding the number of greater elements to the right is too standard to be a D2D, and yes it will be a slightly harder B but will make it not a speedforces at least. And making it a B1B2 is a great idea as the other reply mentioned. (And after considering now, yes the constraints is just alright I was just salty I didn't focus on it)

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

        It adds almost nothing to the problem other than having to know a very standard technique. We don't want a D2B-level idea problem to require a D2D-level data structure, just because a solution for the harder version using such a structure exists.

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

          To be fair, a lot of data structures other than pbds can also solve this in $$$O(nlog(n))$$$ (there are at least $$$2$$$ different segment tree solutions, for example), but I still definitely agree that having this as just div2B would be too hard, and my easy/hard version idea probably isn't actually that great either.

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

couldn't solve B

I'm screwed

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

For B I was trying to get traverse till the first decreasing slope (i,e. traverse till A[i] < A[i+1]). And then my peak would be A[i]. Any number greater than this peak also is to be deleted. This failed on pretest(3). So I would love new ideas ?

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

288174453 When I submit D2 at the last minute:

Passed pretests 1-7 ... :)

MLE in 8 :((

Lesson: use vectors to handle DP with uncertain array lengths ; )

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

How to solve D1

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

    You can solve it using DP + Prefix sum, it will run in either $$$O(N * M * log_2(N))$$$ or $$$O(N * M)$$$.

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

Can someone tell me what's wrong with my D1?

Solved it. nevermind

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

D2 is a good problem.

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

    I agree, even though I struggled hard to debug it (eventually managed; it's also the first time I managed to make a debugger throw an exception, and it was completely my fault).

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

jiangly ORZ :0

»
18 months ago, hide # |
 
Vote: I like it -15 Vote: I do not like it

Why $$$O(n^2)$$$ in B, eventhough it's easy to solve in $$$O(n)$$$ ?

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

I finally solved C by sorting the edges, but I wonder why the bfs solution got a TLE?

288136031

I used discretization to avoid map<ll, vector<ll>>, but then I got 3 MLE :(

288160146

Can anyone help me with the time complexity or the memory use of my solution?

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

    Before pushing y, you should check if it is already visited . If not,then push y into the queue and mark it as visited. You can use a set to do so

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

    is there any reason to avoid map<ll, vector>

    I have used it and got it accepted

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

Could someone please explain their D2 approach?

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

Did anyone solve C with DP? Please share your approach!

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

Very inspiring contest! I love it!

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

I'm like a little baby,don't konw d1 why?

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

dpforces

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

Thank you very much for the contest.

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

ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh i passed c with map but got tle with umap ahhhhhhhhhhhhhhhhhhh

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

Nice shirts :)

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

For Problem C, I submitted the same code in contest, it got TLE'd. And when I submitted the same solution in practice, it got accepted.

Can anyone explain the reason behind it? Thank you!!

TLE submission

Accepted submission

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

    Looks like a c++20 vs c++17 issue.

    idk why this happens tbh tho

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

    Somebody submitted a hack in the last 4 seconds of the contest to TLE an unordered_map solution. It seems that maybe the hashing function works differently in different C++ versions, so when you changed the version it passed.

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

Solved A & B in 8 minutes but couldn't do C because I forgot to keep track of visited for my BFS solution :(

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

I reached blue with this one :D

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

I just want to understand, how my rating dropped if I solved 1 problem (A) say (+100pts) and then gave 1 wrong submission on B (-50pts). I got -44 delta. So I'll be glad if someone explains the drop.

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

I hate DP

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

Problem C, Most of the codes have used dfs, I used bfs and got MLE.

I used the same adjacency list as others using map. The map will contain atmost 3e5 elements, The queue can have a maximum of 3e5 elements at a time. So that shouldn't give MLE. What am I missing here?

Submission Link : https://mirror.codeforces.com/contest/2027/submission/288164685

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

    I also got MLE on pretest 5 while using a queue . Then I switched to a priority_queue and removed all occurrences of the currently visited index from the map so that I don't revisit same index twice, which led me to get an AC. Hope it helps.

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

    You're setting vis[ind] = 1 only when it's popped from the queue, so your queue might contain something like $$$\mathcal{O}(2^n)$$$ numbers on that test since you're adding a lot of duplicates. Maybe if you move that line to where you're pushing into the queue, then it will pass.

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

Overall very nice round!

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

Tomorrow morning КГБ knocks on the door of the author of problem B (Stalin Sort)...

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

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

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

I liked the contest, (luckily) there wasn't much diff for me between $$$D1$$$ & $$$D2$$$.
What is the chance of getting $$$+3$$$ or more after rating roll back?

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

please rename title of contest as "Educational DP Contest — AtCoder"

»
18 months ago, hide # |
 
Vote: I like it +26 Vote: I do not like it

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

Wait who even consensually name themself nathan_higgs like this name is weird man

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

How to do B if the bounds were more strict?

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

I would like to report suspected cases of cheating in Codeforces Round 982 (Div. 2). I have identified multiple pairs of submissions with identical or nearly identical solutions. Here are the relevant submission links:

Pair 1: https://mirror.codeforces.com/contest/2027/submission/288161794 https://mirror.codeforces.com/contest/2027/submission/288145385

Pair 2: https://mirror.codeforces.com/contest/2027/submission/288152323 https://mirror.codeforces.com/contest/2027/submission/288137323

Pair 3: https://mirror.codeforces.com/contest/2027/submission/288163896 https://mirror.codeforces.com/contest/2027/submission/288155729

Each pair of submissions shows a high degree of similarity.

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

Finally, I'm Pupil!!