### thanhchauns2's blog

By thanhchauns2, 2 months ago,

# Hi Codeforces!

_dlbm17, DeMen100ns, SPyofgame and I are delighted to invite you to participate in Codeforces Round #812 (Div. 2).

This contest is brought to you by:

Special thanks to:

The score distribution is 500-1000-1750-2000-2500-3000

Hope to see you in final standings!

UPD: We have a small gift for a Vietnamese participant who have the highest score, so if it is you, please DM me after contest. Good luck everybody!

UPD2: Editorial

UPD3: Congratulations to the winners!

Div.2:

Div.1 + 2:

• +845

By thanhchauns2, history, 3 weeks ago,

# Hi there!

In this blog I would like to share some of the code snippets that can shorten your time in future contests. Of course, I'll ignore the "international snippets"

like:

Sometimes you may find typing the identical thing again and again is boring, this blog is about some method that a few people use to get rid of them (or just only me).

So, let's get started.

Snippet
Usage

Snippet
Usage

Snippet
Usage

Snippet
Usage

Snippet
Usage

Snippet

Snippet

#### Longest Strictly Increasing Subsequence

Snippet

Some snippets are mine, some are taken from the internet. If you want to add some snippets on the blog, please let me know in the comment section.

A little surprise

• +37

By thanhchauns2, history, 3 months ago,

# Hi codeforces!

Wave

### This blog is about a free product that I want to share to everybody.

About 18 months ago I started to learn CP, from then I usually practice the problems 6 hours a day while listening to my favourite song via discord. I used the Maki discord bot:

Maki

The quality was good, but I cannot shuffle or pause the music, which is a bit uncomfortable for me. And I found out that every music bot out there is lack of some purpose, as they are premium features.

### So I decided to make a new one.

Nymphosic
Features

It is a fully-functional discord for playing music. And it does not just play music!

n!search

The music functions are all-free, as well as other functions, which is in developing. As my purpose is to make a free bot for everyone, there will be no premium features.

### You can invite the bot here:

If you like the product, buy me a coffee via

VISA

Sorry for my bad English, hope you will enjoy it.

From Hanoi with a little wind.

Best regards,

thanhchauns2

• +110

By thanhchauns2, history, 4 months ago,

Hi everyone,

The story is, I published my proposion on 28th August 2021, and it haven't been any contributor attached to it yet. Since 8 months is a long time, I'm wondering some questions here:

• How long did other authors have waited until some coordinators attached to their round?

• Is the queue really long?

• If there are any admin reading this, is my round rejected for some reasons? I have written for about ~20 problems, I would really sad if it is not in your plan.

The ID of the our contest is: 1303.

UPD: It's now round Codeforces Round #812.

• +145

By thanhchauns2, history, 8 months ago,
A small confession

## A. Polycarp and Sums of Subsequences

The first two numbers cannot be produced by a sum operation, so we have $2$ of $3$ numbers we must find. How to find the last one? Subtract these two from the largest one.

Implentation

## B. Missing Bigram

We need to create an empty answer string.

Starting from the first substring, for each substring follows, if the first character of it equals the last character of the currently answer string, add the last character, otherwise, append the whole string.

In the end, check if the answer string has the length n or not. If not, repeat the last character.

Be careful of the case we didn't add any whole substring.

Implentation

## C. Paint the Array

The most likely answer for each case is the gcd of all odd-indexed elements or the gcd of all even-indexed elements.

Our work now is to check if it is divisible by some "neighbor index" or not.

Implentation

## D. Array and Operations

We need to optimize two things: the numbers we use in $k$ operations must be as large as possible, and the total result of $k$ operations must be as small as possible.

Thus, we will use $2k$ largest numbers.

Implentation

## E. Singers' Tour

We have a system of equations, it goes like this:

If we add all of them, we will have something like:

Moreover, if we subtract two neighbor equations, for example, the first from the second equation, we will get something like this:

Using this we can calculate all numbers from $a_1$ to $a_n$. Of course, we will have to check the exceptions: $n*(n+1)/2$ is not divisible from the sum of all elements from $b$, or some $a[i]$ is non-positive.

Implentation

## F. Reverse

If $x = y$, the answer is YES.

Else if $y$ is divisible by $2$, the answer is NO.

Else we have to check if the binary string $s$ of $x$ can convert into the binary string $t$ of $y$ or not, with $s$ we can convert into several "starting strings":

1. Itself.

2. Itself, with one extra '1' at the end.

3. Itself but erase all '0's at the end.

4. Itself, erase all '0's, reversed.

Clearly, the operation is to choose to keep the string or erase all the '0's at the end then add some '1's (maybe zero) to the beginning or the end of the string.

The work now is to check each case if we can obtain $t$ by adding '1's to the beginning or the end of the current string.

Implentation

A simple way to solve: use two sets, both store vectors of four elements: the leftmost index of the segment, the rightmost index of the segment, how many numbers we take from it, and the distance between it and the next segment on the array. The first set will sort by the distance, the second set will sort by their first elements.

So how to use them? At first, merge the two arrays a and b into 1 array, let's call it TTL, use a map to save if we are currently have something or not. Then for each element, we will make a segment based on them: the leftmost and rightmost is their index, the number of elements we will take is either 1 or 0 depending on the map I described above, the distance will be the difference between it and the next number in TTL.

What will we do now? Solve the problem offline, for each query merge some of the segments which have the smallest "distance" into some other segments, so there will be no more than N merges. Since we are using sets, the complexity is O(NlogN).

To calculate the sum efficiently, use a prefix array.

Implentation

Hope that my defines are not difficult to understand.

Yes, I'm a fan of neal_wu.

• +50

By thanhchauns2, history, 12 months ago,

Hi everyone, recently I came across this problem in the problemset, which I have came up with a solution like this: 125580675, which turned out to be RTE on test 7 in the system tests. I managed to copy the test to run and debug it locally, but it gave a correct answer and didn't help me anything.

The #7 test looks like this:

Test case #7

My solution on local IDE output this solution:

Output

For everyone who is reading this, excuse me, can you help me find the bug? I couldn't find it however I try.

Thank you so much for reading this! Hope you have a great standing in the next contests ^_^

• -19

By thanhchauns2, history, 12 months ago,

I just want to share something to community, after I found this problem in the problemset (which the answer cannot be display as long long integer). Here is my class to calculate on strings (including add, substract, multiply, divide (as two strings), modulo and take gcd, I will add bitwise operators later if possible).

Hope you will find it useful. If you find this incomplete, I would love to read any feedback.

Code

• +24

By thanhchauns2, history, 13 months ago,

Or I will shave my hair.

• +301

By thanhchauns2, history, 13 months ago,

I tried to add the 100s and 0s one by one, since $n$ does not exceed $10^6$, solving it by using heaps does not cost so much time. Here it is: 122955494.

Have a nice day! Please don't downvote me :(

• +17

By thanhchauns2, history, 13 months ago,

Hi, I'm just wonder how much time the people here need to reach CM. I have stuck with this 1700-1750 elo for 2 weeks, maybe it'll be more. Could you please share your story and your experience of how you you gone so far and achieve such high ratings? I would love to learn from any.

Thanks for reading this dumbsh*t blog.

P/s: I hope to reach CM in less than 5 months, is it possible or just illusory?

P/s 2: Sorry if this blog makes you feel inconvenient. My English is bad :(

• -25

By thanhchauns2, history, 14 months ago,

It's literally resubmit everyone's code. My latest submission for practice has been in queue for 30 minutes lol.

Still submitting.

• +52

By thanhchauns2, history, 14 months ago,

I am current looking for some Discord servers which has been built for CP community, but I haven't found any. Can anybody suggest me some? Thank you!

Sorry for my bad English T-T

P/s: I wonder why posting searching for a learning community on codeforces is badly downvoted :/ Is it a hated topic? If it is, I will remove it :(

• +22

By thanhchauns2, history, 14 months ago,

He told my whole family, I don't know whether to laugh or to cry :(

• +197

By thanhchauns2, history, 15 months ago,

Given a map of a dungeon, your task is to take all TWO diamonds in the dungeon.

Find the minimum number of gates you have to open to take all the diamonds.

Note: It can be more than one gate to go into the dungeon from the outside.

You can move up, down, left, right.

• The letter '.' means blank space, you can move on it

• The letter '*' means blockade, you have to go around it

• The letter '#' means there's a gate at that place, you need it opened to go through it

• The letter '\$' means the diamond.

Input format:

• First line is two number N and M — the dungeon has the size N*M. (2 ≤ N,M ≤ 100)

• N lines following, represent the map of the dungeon.

Output format:

• A single integer — the minimum number of gates you have to open.

Example input:

5 9

****#****

..#.#..

****.****

$#.#.#$

Sorry for the input, you can see read the input here : https://ideone.com/EXk0Wh

Example output:

4

Thank you guys, hope you have a great standing in the next contest.

• +7

By thanhchauns2, history, 16 months ago,

Magnus is the youngest chess grandmaster ever. He loves chess so much that he decided to decorate his home with chess pieces. To decorate his long corridor, he decided to use the knight pieces. His corridor is covered by beautiful square marble tiles of alternating colors, just like a chess board, with n rows and m columns. He will put images of knights on some (possibly none) of these tiles. Each tile will contain at most one knight.

The special thing about his arrangement is that there won’t be any pair of knights can attack each other. Two knights can attack each other if they are placed in two opposite corner cells of a 2 by 3 rectangle. In this diagram, the knight can attack any of the Xs.

Given the dimension of the long corridor, your task is to calculate how many ways Magnus can arrange his knights. Two arrangements are considered different if there exists a tile which contains a knight in one arrangement but not in the other arrangement (in other words, rotations and reflections are considered different arrangements).

Input

Each input will consist of a single test case. Note that your program may be run multiple times on different inputs. Each test case will consist of a single line with two integers n and m (1≤n≤4, 1≤m≤10^9) representing the dimensions of the carpet. There will be a single space between n and m.

Output

Output a single line with a single integer representing the number of possible arrangements, modulo (10^9+9).

Sample Input 1

1 2

Sample Output 1

4

Sample Input 2

2 2

Sample Output 2

16

Sample Input 3

3 2

Sample Output 3

36

He said I need to Divide and Conquer, however I got no idea about that.

• -31

By thanhchauns2, history, 16 months ago,

Given an array with N elements and a number P (P ≤ N). Pick randomly P elements from the array, let's call T the product of these elements. Find the largest x that T % 10^x = 0

Example:

Input

3 2

26 5 96

Output

1

Input

3 2

25 4 90

Output

2