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

Автор ACGN, история, 22 месяца назад, По-английски
A little backstory about the round (ACGN)

2031A - Penchick and Modern Monument

Idea: pwned
Preparation: HappyPacMan

Hint 1
Hint 2
Solution
Feedback

2031B - Penchick and Satay Sticks

Idea: ACGN
Preparation: HappyPacMan

Hint 1
Hint 2
Solution
Feedback

2031C - Penchick and BBQ Buns

Idea & preparation: ACGN

Hint 1
Hint 2
Solution
Feedback

2031D - Penchick and Desert Rabbit

Idea: Saudi
Preparation: HappyPacMan

Hint 1
Hint 2
Solution
Feedback

2031E - Penchick and Chloe's Trees

Idea & preparation: ACGN

Hint 1
Hint 2
Solution
About Problem E
Feedback

2031F - Penchick and Even Medians

Idea: trunkty
Solution & preparation: maomao90

Hint 1
Hint 2
Solution 1
Solution 2
Solution 3
Challenge
Feedback

Round statistics

Fastest submission among all participants, and among rated participants:
A: tourist at 00:00:43, priyanshu.p at 00:00:56
B: tourist at 00:01:57, arnabmanna at 00:02:10
C: arvindf232 at 00:06:22, boboquack at 00:11:42
D: _Duck_Dot_Dot_Happy at 00:10:50
E: fzx at 00:11:27, Jack.YT at 00:20:38
F: peti1234 at 00:34:01, waiting_for_the_sunset at 00:54:34

More round statistics to be updated!

That's it for this round, and we hope you had fun with all the problems!

A few serious words from ACGN - about problemsetting, MathForces, and more
and from my own heart...

Разбор задач Codeforces Round 987 (Div. 2)
  • Проголосовать: нравится
  • +282
  • Проголосовать: не нравится

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

wow,the tutorial comes so fast!

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

great contest c is quite interesting

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

Why the hints of D starts from Hint 2? By the way, good C&D.

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

why my code for C got wrong answer?

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

superfast editorial

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

C was great. The Pythagorean triples idea is so elegant.

»
22 месяца назад, скрыть # |
Rev. 2  
Проголосовать: нравится +1 Проголосовать: не нравится

Nice trick on C. Instead of creating this array

1 3 3 4 4 5 5 6 6 1 2 7 7 8 8 9 9 10 10 11 11 12 12 13 13 1 2

I create this

1 2 2 3 3 4 4 5 5 1 6 6 7 7 8 8 9 9 10 10 11 11 12 13 13 1 12

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

the fastest tutorial ever!

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

[1, 2, 3, 3, 1, 2, 4, 4, 1] is sollution for 9 which is less then 25 for problem C

distance is 1 for 3, 4 and 4 for 1, 2

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

I find I always make problem more complex, like this div.2 D. I spent 30mins to solve ABC, but can't wock out D. What should I do to avoid??

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

    What algorithm you think it should be applied in D?

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

      I preprocessed out the position of the largest number and sorted it by numerical size and position. Then use a monotonic stack to maintain a suffixed minimum value from back to front. When I want to compute the answer, find the position of this minimum and find the answer before it. The time complexity is $$$O(n\log{n})$$$ because I need to make a binary search inside the stack to find this rearmost minimum.

      • »
        »
        »
        »
        22 месяца назад, скрыть # ^ |
        Rev. 3  
        Проголосовать: нравится +3 Проголосовать: не нравится

        At first, I thought the same thing however I notice that I can create mountains (*mountain is an decreasing array), so a mountain will have a peak (the largest value) and a down (the smallest value).

        For example: 2 4 1 6 3 8 5 7 -> (2), (4, 1), (6, 3), (8, 5), (7)

        And then I save the largest and smallest of each mountain

        (2), (4, 1), (6, 3), (8, 5), (7) -> (2, 2), (4, 1), (6, 3), (8, 5), (7, 7)

        Here's another example 2 5 3 1 6 2 10 9 8 -> (2), (5, 3, 1), (6, 2), (10, 9, 8)

        Then (2), (5, 3, 1), (6, 2), (10, 9, 8) -> (2, 2), (5, 1), (6, 2), (10, 8)

        And I notice that if there exist 2 mountains i and j so that i.peak > j.down then the rabbit can jump from mountain i to mountain j. I sort these mountains with the peak decreasing and I find out that the problem now looks like a graph (more like DSU).

        Here's my solution 291628412

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

        I use this algorithm too!

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

Can D be solved with dsu?

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

    Yep. For each point, merge it with the point to the left of this point and with the highest height, and also merge it with the point to the right that is farthest away from it and with a height smaller than it. It can be shown that this merging is optimal.

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

Lmaooooo I already knew that tons would vote "Bad Problem" in the feedback for C. This community can be so predictable at times.

C is an EXCELLENT problem, yall are just haters

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

    Yes, many of them don't think about the odd amount of elements can have a solution

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

    So true bestie

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

    What is the purpose of samples in such problems? They always must have funny non generalizable construction.

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

      Well of course it has to be non-generalizable, otherwise it would spoil the problem haha

      Regardless, it does still serve the following purposes:

      • Showcases the output format
      • Allows you to verify ("sanity check") that your understanding of the problem is correct, since you can verify the given definition on a concrete example.

      For example in this problem, what does |i — j| = a perfect square mean? Should it be the 1st and 9th buns that match, or the 1st and 10th? We know it should be 1 and 10, but it's a reasonable misunderstanding to make, especially in the heat of a contest.

      But the answer is easily, totally unambiguous because you can very easily just check the sample output to see which interpretation is correct.

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

Typo: In Problem F Solution 1 Part 1 line 2: and the other is strictly larger than $$$\frac n2$$$ -> larger than $$$\frac n2 +1$$$.

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

if you know Pythagoras theorem,you can solve C easily

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

Penguins! A very nice contest :D

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

Though I stuck on C for nearly an hour(because of my poor math), I still think C is a beautiful problem conbined maths and constructive algorithms excellently. This is the best problem in this type I've ever met.

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

Can someone point out the mistake —

#include <bits/stdc++.h>
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    cin >> t;
    while (t--) {
        int n;
        cin>>n;
        int count=0;
        vector<int>arr(n);
        for(int i=0;i<n;i++){
            cin>>arr[i];
        }
        for(int i=0;i<n-1;i++){
            if(arr[i]>arr[i+1]) count++;
        }
        cout<<count<<endl;
    }
    return 0;
}
»
22 месяца назад, скрыть # |
Rev. 3  
Проголосовать: нравится 0 Проголосовать: не нравится

For C, isn't [1, 2, 2, 4, 4, 5, 5, 3, 6, 1, 7, 7, 6, 1, 9, 9, 3] for 17?

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

Thanks for the fast editorial. Elegant problemsetting for C, now I learn.

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

What's wrong with this case for n=27 in Problem C? 13 1 2 2 3 3 4 4 5 5 1 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 1

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

Unfair time constraints for B, my correct solution [O(N) in PyPy] is giving tle on test 3, kindly accept this in system testing. (https://codeforces.me/contest/2031/submission/291630383) Wasted the whole contest in figuring out a logn or constant time solution for this, I didn't even try using C++ cause never do I expect a simple O(N) problem to give tle just because its python, also got like extra -200 because of trying shorter solutions for B out of frustration, so sad

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

In Problem D first example

4

2 3 1 4

o/p --> 3 3 3 4

how can rabbit jump from 2 to 3 because question clearly states that forward jump can be made iff the next guy is smaller.

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

Great problem C, good choice of samples as well, any more samples might've given away the solution.

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

E can be solved in $$$O(N)$$$

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

    how so? I'm interested

    • »
      »
      »
      22 месяца назад, скрыть # ^ |
      Rev. 5  
      Проголосовать: нравится +3 Проголосовать: не нравится

      Please have a look at 291664548

      Basically, we just count the leaves needed for each subtree. The # can be large so we use a binary array.

      Since the count added from each children is a power of two, by potential method the amortized time to do addition of all children is $$$O(#children)$$$.

      Then we can just choose smallest $$$k$$$ such that $$$2^k$$$ leaves is enough.

      Edit: I've just noticed the code above has a mistake: It has an unnecessary loop in dfs of O(d)

      However it can easily be fixed, as in 291671084

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

        I'm sorry, I really can't understand the code; can you explain it in more detail and pseudocode? thankss

        • »
          »
          »
          »
          »
          22 месяца назад, скрыть # ^ |
          Rev. 4  
          Проголосовать: нравится +14 Проголосовать: не нравится

          Sure, dfs(u) returns depth of perfect binary tree needed to build subtree of u in original tree.

          Let's call this value dp[u].

          To calculate dp[u], first we calculate dp[v] for every child v. The intuition is if v requires perfect binary search tree of depth dp[v], it will "consume" 2^{dp[v] - 1} leaves.

          We add the amount of leaves needed for each child node of u to get the total amount of leaves needed for u's subtree.

          But the amount can be very large, so we use something similar to bigint in base 2.

          dfs(u) {
          	d <- 0
                  vec <- {}
          
          	for all child v {
                          x <- dfs(v)
                          vec.push_back(x)
          		d = max(d, x)
          	}
           
                  let xx be bigint
                  for w in vec {
                         add 2^w to bigint
                         d = max(d, w)
                  }
          
          	if (d-th bit of xx is on and there are more than one bits turned on) {
                         /* basically, xx is more than 2^d */
                         d += 1
                  }
          		
          	return d + 1;
          }
          
          

          (There might be some off-by-one error in this comment)

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

ACGN i can't view the implementation of problems,can you make them public?

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

if this round didnt have samples, nothing would have changed

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

I finished ABCD for the second time!

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

Why are there so many pretests in Problem E?

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

Thanks for creating this round!All of the problems are awesome!

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

In the solution for D Shouldn't it be:

ansi=max(a1,a2,…ai)=pi

instead of

ansi=max(a1,a2,…an)=pi

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

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

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

In D ansi=max(a1,a2,…an)=pi. should be ansi=max(a1,a2,…ai)=pi.

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

in A if i assume if n == 1, the answer will always be 0, but due to this i got the wrong answer, why is that? my answer got accepted after i removed this condition

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

Can someone help me figure out why 291650692 failed with RTE, while 291666454 passed? The only difference is that the priority_queue is declared local in the former and global in the latter. Is this because $$$10^6$$$ ints is too much for a stack allocated std::priority_queue?

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

good luck on your medicine journey. amazing story!

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

I think the definition of rooted tree isomorphism given in 2031-E - Penchick and Chloe's Trees is slightly wrong.

Two rooted trees, rooted at $$$r_1$$$ and $$$r_2$$$ respectively, are considered isomorphic if there exists a permutation $$$p$$$ of the vertices such that an edge $$$(u,v)$$$ exists in the first tree if and only if the edge $$$(p_u,p_v)$$$ exists in the second tree, and $$$r_1=p_{r_2}$$$.

Here $$$u$$$ and $$$v$$$ are in the first tree, and $$$p_u$$$ and $$$p_v$$$ are nodes in the second tree. But then $$$r_1=p_{r_2}$$$ makes no sense since $$$p:$$$ first tree $$$\rightarrow$$$ second tree. The correct statement is $$$p_{r_1}=r_2$$$

»
22 месяца назад, скрыть # |
Rev. 3  
Проголосовать: нравится +10 Проголосовать: не нравится

I solved F with a solution with success rate of around $$$0.998$$$.

Denote $$$A$$$ as the set of candidates for $$$\frac{n}{2}$$$ (initially $$$ {1, 2, \dots, n}$$$). Similarly denote $$$B$$$ as the set of candidates for $$$\frac{n}{2} + 1$$$. We also maintain the third set $$$C$$$ of candidates for both $$$\frac{n}{2}$$$ and $$$\frac{n}{2} + 1$$$ (we will update it a bit differently, so it won't be just $$$A \cup B$$$).

Query a random subset $$$S$$$ of $$$C$$$ of size $$$10$$$. Let $$$x$$$ and $$$y$$$ be the result. If $$$x = \frac{n}{2}$$$ or $$$y = \frac{n}{2}$$$, there is $$$\frac{n}{2}$$$ in $$$S$$$, so we can set $$$A = A \cap S$$$. Similarly do for $$$B$$$. If $$$x = \frac{n}{2}$$$ and $$$y = \frac{n}{2} + 1$$$, then we can set $$$A = A \cap S \cap (A \cup B)$$$ and $$$B = B \cap S \cap (A \cup B)$$$ (actually, that does nothing).

We don't wanna keep $$$C$$$ too big, but also don't want to make it too small to have a higher chance to reduce the sizes of $$$A$$$ and $$$B$$$. What I do is: if $$$x \lt \frac{n}{2}$$$, $$$\frac{n}{2} + 1 \lt y$$$ and $$$|C| - |S| \ge 12$$$, set $$$C = C \setminus S$$$. Otherwise, do nothing.

Terminate the search when $$$|A \cup B| = 2$$$.

Out of $$$10000$$$ random tests with $$$n = 100$$$, it manages to solve around $$$9980$$$. Submission: 291665018

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

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

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

why my code for C got wrong answer?

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

for me, problem E much more easy then D))

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

C was so beautiful, was not able to solve it in the contest but the solution is elegant!

W problem @ACGN, keep it up!

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

I think D is easier than everything

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

Note that we don't need to dfs in Problem E since 1..n is a topo seq of the tree

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

The best C I've ever done 有生之年做过最好的C题

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

Problem B also can be solved by brute force, because one number can never be swapped more than twice, so we just need to check the array two times and swap two numbers if we can, time complexity $O(n)$。

code:

void solve(){
    int n;
    cin>>n;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int t=1;t<=2;t++)
    {
        for(int j=1;j<n;j++)
        {
            if(a[j]==a[j+1]+1)swap(a[j],a[j+1]);
        }
    }
    writeln(is_sorted(notall(a))?"YES":"NO");
}
»
22 месяца назад, скрыть # |
 
Проголосовать: нравится +6 Проголосовать: не нравится

D is a cute problem. Thanks.

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

Can any body explain why my code is wrong ?

Problem D : 291848242

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

Please someone help me with this,why my 291854656 is WA ? Below code seems to be correct to me. Please provide a testcase where it fails . Thanks

#include<bits/stdc++.h>
using namespace std;
 
#define fastio ios_base::sync_with_stdio(0); cin.tie(0)
#define LL long long 
#define mod 998244353 
#define FOR(i, j, k) for (int i=j ; i<k ; i++)
#define ROF(i, j, k) for (int i=j ; i>=k ; i--) 
 
const long long INF = 1e18;
const long long MAX = 1e5+10;

int main(){
    fastio;
    int t; cin>>t;
    while(t--){
        int n;cin>>n;
        int a[n+1];
        bool ok=true;
        FOR(i,1,n+1) cin>>a[i];

        FOR(i,1,n){
            if(a[i]==i)
                continue;
   
            if(i==a[i+1]){
                 swap(a[i],a[i+1]);
            }
            else{
                ok=false;
            }
        }
        cout<<(ok?"yes":"no")<<"\n";
    }
}


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

The last method given by the answer to question A if the test case is 1 5 4 4 1 4 shouldn't the output be 2? Why is its code output 3

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

There is something wrong with the LaTex of problem E claim 1's proof. Please fix it. Thank you!

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

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

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

Perhaps there is something wrong with the first way to slove E in your tutorial. After reading your code, maybe we should replace $$$a$$$ by $$$\lceil \frac {a}{2^{d_{c_i}-b}}\rceil + 1$$$ but not $$$\lceil \frac {a}{2^{d_{c_i}-b}}\rceil$$$

In Simplified Chinese: 楼主你E题第一种解法好像有个地方写的有问题。我看了你的代码之后,觉得有个地方教程里写的和你代码写的不符:我们应该把 $$$a$$$ 改成 $$$\lceil \frac {a}{2^{d_{c_i}-b}}\rceil + 1$$$ ,而不是 $$$\lceil \frac {a}{2^{d_{c_i}-b}}\rceil$$$

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

Good problem C.

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

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

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

We can you simple rangeMax segtree to solve problem D,

we just have to simulate , first go to max element in the left , then for every possible value from 1 to maxelement , take the value from previously element we have jumped

link: link

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

Could anyone give me a small test where my code for E fails? Thanks in advance

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

A dumbed down version of solution 1 for F that also comfortably passes:

  • Randomly query quartets until you find one which has the smaller median $$$m_1 \lt n/2$$$ and larger median $$$m_2 \gt n/2 + 1$$$.
  • Do part 2 of solution 1 using this quartet instead of a pair

xd