__baozii__'s blog

By __baozii__, history, 5 weeks ago, In English

We hope you enjoyed the problems!

Rate the contest!

2209A - Flip Flops

Solution
Code (C++)
Rate the problem!

2209B - Array

Solution
Code (Python)
Code (C++)
Rate the problem!

2209C - Find the Zero

Solution
Code (Python)
Rate the problem!

2209D - Ghostfires

Solution
Code (C++)
Rate the problem!

2209E - A Trivial String Problem

Solution
Code (Python)
Rate the problem!

2209F - Dynamic Values And Maximum Sum

Solution
Code (C++)
Rate the problem!

Full text and comments »

  • Vote: I like it
  • -64
  • Vote: I do not like it

By __baozii__, 3 months ago, In English

We hope you enjoyed the problems!

Rate the contest!

2188A - Divisible Permutation

Solution
Code (Python)
Rate the problem!

2188B - Seats

Solution
Code (C++)
Rate the problem!

2187A - Restricted Sorting

Hint 1
Hint 2
Solution
Code (Python)
Rate the problem!

2187B - Shortest Statement Ever

Hint 1
Solution
Proof of the interesting fact
Code (C++)
Rate the problem!

2187C - Jerry and Tom

Hint 1
Hint 2
Solution
Code (C++)
Bonus
Rate the problem!

2187D - Cool Problem

Solution
Code (C++)
Rate the problem!

2187E - Doors and Keys

Hint 1
Hint 2
Hint 3
Solution
Code (Python)
Bonus
Rate the problem!

2187F1 - Al Fine (Maximizing Version)

Hint 1
Hint 2
Hint 3
Hint 4
Hint 5
Solution
Code (C++)
Fun Fact
Rate the problem!

2187F2 - Al Fine (Counting Version)

Solution
Code (C++)
Bonus
Rate the problem!

2187G - Many Cartesian Trees

Solution
Code (C++)
Rate the problem!

Full text and comments »

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

By __baozii__, history, 3 months ago, In English

Hello, Codeforces!

We are happy to invite you Baozii Cup 3, which will take place on Jan/25/2026 08:00 (Moscow time).

You will have $$$5$$$ hours to solve $$$13$$$ problems, including at least one interactive problem.

This is a team contest following ACM/ICPC rules, with teams of up to $$$3$$$ members. The penalty for an incorrect submission is $$$20$$$ minutes.

The standings will be frozen for the last $$$60$$$ minutes of the contest.

Most problems are created and prepared by me, with help from Bronya_H, zeemanz, and 0.1w33hw3.

We would like to thank:

Registration

If you are living in China or have a WeChat/QQ account, you may register by filling in this form. Otherwise, you may register by filling in this form. Please do not fill in both forms.

Notes

  • You may attempt past contests at Baozii Cup 1 and Baozii Cup 2.

  • If you have any queries regarding the contest, please send a private message on either Codeforces or WeChat.

Good luck and have fun!

UPD 1: Everyone who has registered should have received an invitation link in their private messages. Please message me if you are not invited.

UPD2: Here is the contest link: Baozii Cup 3. If you didn’t register for the contest, you may also view the scoreboard via the link above.

UPD3: Note that rules about third party code for Codeforces still apply in this contest. If you are found out using LLM-generated code, you will be sent to cry's basement. For any queries regarding problem statements, please ask in the clarifications section.

UPD4: The contest has ended. The problems have been uploaded to gym. Please leave any feedback in the comments section!

Full text and comments »

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

By __baozii__, 9 months ago, In English

Hello Codeforces!

We are glad to invite you to participate in Codeforces Round 1042 (Div. 3), which will start on Aug/10/2025 17:35 (Moscow time). You will be given 2 hours and 15 minutes to solve 8 problems.

The problems are authored and prepared by -firefly-, efishel, Tobo, and __baozii__.

The round will be hosted by the rules of educational rounds (extended ICPC). Thus, all solutions will be judged on preliminary tests during the round, and after the round, there will be a 12-hour phase of open hacks. After the open hack phase, all accepted solutions will be rejudged on successful hacks. Also, note that there is no score distribution — rank will be determined by number of problems solved, followed by penalty; wrong submissions will incur the usual penalty of 10 minutes, following the rules of educational rounds.

As a reminder, only trusted participants of the third division will be included in the official standings table. This is a compulsory measure for combating unsporting behavior. To qualify as a trusted participant of the third division, you must:

  • take part in (and solve at least one problem in) at least five rated rounds;
  • and not have had a rating of 1900 or higher at any moment in time.

Regardless of whether you are a trusted participant of the third division or not, if your rating is less than 1600, then the round will be rated for you (unless you register unrated).

Also, note the rule restricting the use of AI. If you are caught breaking this rule, you will be thrown into -firefly-'s basement. For your own well-being, I suggest adhering to the rules.

We would like to thank the following people for helping make this round possible!

Good luck!

UPD: Editorial

Full text and comments »

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

By __baozii__, history, 10 months ago, In English

Introduction

This blog is inspired by this blog, which is an interesting constructive problem:

  • How to construct a DAG with no multiple edges, such that there exists exactly $$$k$$$ distinct paths from vertex $$$1$$$ to $$$n$$$?

Obviously, there is a trivial solution which requires $$$2k$$$ edges and $$$k+2$$$ vertices. Simply connect vertex $$$1$$$ to each vertex numbered from $$$2$$$ to $$$k+1$$$, then connect each of these vertices to vertex $$$k+2$$$. In this blog, we shall discuss how to minimise the number of edges used.

Using no more than $$$4 \log k+1$$$ edges

This is likely to be the first way that many people will approach this problem. Consider the following structure:

There are exactly $$$2$$$ distinct paths from $$$1$$$ to $$$3$$$. If we chain them together as such:

There will be $$$2^3=8$$$ distinct paths from $$$1$$$ to $$$7$$$. We can see that it is possible to create $$$2^m$$$ paths using $$$3m$$$ edges.

For simplicity, we will call the chain $$$1 \to 3 \to 5 \to 7 \to \dots$$$ as the backbone, and $$$v_i$$$ to be the $$$i$$$-th vertex from $$$1$$$ on the backbone. For example, $$$v_0=1$$$, $$$v_1=3$$$, $$$v_k=2k+1$$$.

Using the method above, we can only construct a graph when $$$k$$$ is a power of $$$2$$$. Consider the binary representation of $$$k$$$. We first construct the backbone such that the number of paths has the same most significant bit as $$$k$$$. Then, for every non most significant set bit in $$$k$$$, say its the $$$j$$$-th bit, we add an edge from $$$v_j$$$ to the terminal vertex. For example, for $$$k=11$$$, its binary representation is $$$1011$$$, and we can construct the following graph:

Since for each $$$v_i$$$, there are exactly $$$2^i$$$ path ending at that vertex, we simple connect the positions corresponding to the set bits to the terminal vertex. There is a slight detail: we can't connect $$$v_{b-1}$$$ to $$$v_b$$$, as multiple edges are not allowed. In this case, we need to add another vertex and another edge.

In the worst case, where $$$k=2^p-1$$$ for some integer $$$p$$$, we need $$$4p+1$$$ edges: $$$3p$$$ for the backbone, $$$p$$$ for $$$p$$$ set bits, and $$$1$$$ extra for the detail above.

Can we do better?

The answer is Yes. To utilise edges even more, we need to change the structure of the backbone. After some thoughts, I came up with the following structure:

where $$$i$$$ connects to $$$i+1$$$ and $$$i+2$$$ for all $$$i \le n-2$$$, and $$$n-1$$$ connects to $$$n$$$. It is not hard to see that the number of distinct paths ending at vertex $$$i$$$ would be $$$F_i$$$, the $$$i$$$-th fibonacci number. The proof is left as a small exercise (hint: consider dp).

Using this structure, we can create $$$F_m$$$ paths using $$$2m-1$$$ edges.

Surprisingly, we can still use the binary representation idea above. Just like every integer can be represented by the sum of distinct powers of $2$s, every integer can also be represented by the sum of distinct fibonacci numbers. The theorem is called Zeckendorf's Theorem.

What makes this construction better is that: in the binary method, we need to consider the worst case where all bits are set. However, in the fibonacci method, the number of distinct fibonacci numbers each integer is partitioned into is not that large. In fact, I bruteforced all $$$k$$$ no larger than $$$10^7$$$, and I found that the maximum number of edges used is only $$$83$$$; for randomly generated integers in the range $$$[10^{17},10^{18}]$$$, the maximum number of edges used is $$$199$$$, whereas you need around $$$240$$$ for the binary method (worst case).

I don't have proofs of whether this method will be better for very large $$$k$$$s, like up to $$$10^{100}$$$ in the original blog. If you have explored this problem even deeper or is willing to, please share any interesting discoveries.

Anyways, this is my first blog on Codeforces. It is very coincidental, as I have made this problem on polygon for my friends a few months ago and they rated it around 2400. The constraints in that problem was $$$k \le 10^{17}$$$, and maximum $$$200$$$ edges.

Don't really know how to end off, so just hope everyone's rating grows like fibonacci numbers. Good luck!

Full text and comments »

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