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

Автор thanhchauns2, 4 месяца назад, По-английски

Hello Codeforces!

$$$\newline$$$

Do you know that eating cheese can make you code faster than the running speed of a Tyrannosaurus REX?

It's been a while, today GlowCheese and I are delighted to invite you to participate in Codeforces Round 963 (Div. 2). This round will be rated for all participants with a rating lower than 2100.

Our round will start on Aug/04/2024 17:35 (Moscow time). You will be given 6 problems and 120 minutes to solve them.

This contest is brought to you by Code Mely, a Vietnamese community for Computer Science. Reach out to us here.

Special thanks to:

Score distribution: $$$500 - 1000 - 1500 - 2000 - 2750 - (2500 - 1000)$$$

Hope to see you in the final standings!

UPD1. Editorial is out!

UPD2. Congratulations to the winners:

Div.2:

  1. kkkksc03
  2. imwh
  3. _acsm_
  4. _wrpwrp
  5. rainboy

Div.1 + Div.2:

  1. A_G
  2. arvindf232
  3. Rubikun
  4. kkkksc03
  5. Sugar_fan

Полный текст и комментарии »

  • Проголосовать: нравится
  • +522
  • Проголосовать: не нравится

Автор thanhchauns2, история, 20 месяцев назад, По-английски

Hi, I collected the solutions for the problems of April Fools Day Contest 2023. Before the official editorial being posted, we can discuss about the problems here.

P/s: The editorial was published.

1812A - Are You a Robot?

Solution

1812B - Was it Rated?

Solution

1812C - Digits

Solution

1812D - Trivial Conjecture

Solution

1812E - Not a Geometry Problem

Solution

1812F - Factorization

Solution

1812G - Colour Vision

Solution

1812H - Expected Twist

Solution

1812I - Mountain Climber

Solution

1812J - Unmysterious Language

Solution

Полный текст и комментарии »

  • Проголосовать: нравится
  • +28
  • Проголосовать: не нравится

Автор thanhchauns2, история, 21 месяц назад, По-английски

The first time I cannot participate officially in a Div.2.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +43
  • Проголосовать: не нравится

Автор thanhchauns2, история, 22 месяца назад, По-английски

Not long ago ToxicPie9 posted a blog explaining common mistakes in competitive programming and how to avoid them. I was greatly inspired by that post so I decided to write an episode on my own.

Today I will mention four topics that I learned why practicing Competitive Programming and I will also mention how to build them. Also, in most cases, I will give you a chance to find out what the hard part is before I reveal the culprit as I tried to make this blog interactive. The codes that I have used in this blog have been written in Python as it is the most powerful language for CP.

Segment trees

Definition:

Click me

So how to build a segment tree?

Click me

Basic usage:

Click me

Update on range:

Click me

Fenwick tree

Definition:

Click me

So how to build a Fenwick tree?

Click me

Basic usage:

Click me

More functions:

Click me

Disjoint Set Union

Definition:

Click me

So how to build a Disjoint Set Union?

Click me

Basic usage:

Click me

Treap

Definition:

Click me

So how to build a Disjoint Set Union?

Click me

Basic usage:

Click me

More about data structures in Python:

Although Python is the most powerful language in CP, there are some data structures that we cannot install through pip like sparse table or sqrt decomposition. If such case, we should:

  • Develop a pip package on your own. Since people, including me, are indiscriminately using C/C++ just for compiling speed, they don't know how powerful Python is and just reject it while doing CP. This is why there are a lack of necessary libraries for Python. Your contribution is priceless.

  • Implement you own library. If pip does not solve the problem, you can just implement your own version. Whenever a contest starts, just copy and paste them in. Voila.

  • Convert the current problem to another problem using a library that is solvable by using pip. This requires a lot of experience in Competitive Programming, since it is a hard job to do.

  • Give up Find another way to solve it, don't give up.

Thanks for reading the blog. Feel free to add more mistakes that are common in CP in the comment section.

See you on a later episode, friend!

P.S. Although this is mostly a joke post, I tried to be accurate about the facts and did not intentionally put incorrect information in it (which means you may treat it as a somewhat educational blog). It also aims to showcase some features of Python that helps you avoid some common CP mistakes in languages like C++.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +46
  • Проголосовать: не нравится

Автор thanhchauns2, история, 23 месяца назад, По-английски

Hi Codeforces!

Igorfardoc, Vladithur, Alexdat2000, GlowCheese, DeMen100ns, SPyofgame and me (spelling "thanh-chau-n-s-2") are delighted to invite you to participate in Codeforces Round #842 (Div. 2). This round will be rated for all participants with a rating lower than 2100.

This contest is brought to you by

Special thanks to:

Edit: there will be $$$2$$$ packages for two participants in Vietnam, the highest score and the luckiest. You have to set your region to Vietnam to be qualified.

The score distribution is $$$500-1000-1500-1750-2250-3250$$$.

Hope to see you in the final standings!

Editorial is out.

Congratulations to the winners:

Div.1+2 Div.2
1 arvindf232 drizzlo
2 Hyperbolic jiangly_fan_fan_fan_fan
3 drizzlo BedzieMagikZa2Lata
4 jiangly BeautifulChicken
5 Um_nik AE-3803

And the first solver for each problem:

A B C D E F
Div.1+2 dapingguo8 tourist youknowiknowyouknow A_G nok0 jeroenodb
Div.2 celestialcoder 1024mb youknowiknowyouknow MIOC69 cmk666 drizzlo

Полный текст и комментарии »

  • Проголосовать: нравится
  • +593
  • Проголосовать: не нравится

Автор thanhchauns2, история, 23 месяца назад, По-английски

Hi Codeforces!

Ladies and gentlemen, 2023 is near. Lots of things happened to us in 2022, both achievements and disappointments. This is just a list of what I have done and haven't yet in 2022, and my goals for 2023.

I'm just in the mood to write something, don't take it seriously.

Successful tasks:

  • Have my hair grown back.
  • Being in the top 100 of a contest.
  • Set a div.2 round.
  • Solving every problem of a div.3 contest (with my alt account).
  • Be able to solve some 2400 problems.
  • Overcome my weakness of bitmasks and data structures.
  • Won the 2022 local CP cup at my university.
  • Participate in the 2022 ICPC Asia HCMC Regional Contest.
  • Have my own Computer Science community.
  • My community is a great partner in some big events.
  • Meet my girlfriend.
  • Meet LastDance.
  • Meet GlowCheese.
  • Meet jalsol.
  • Meet SPyofgame.
  • And many more people.
  • Visit home regularly, to see that my parents are still healthy.

What I haven't done:

  • Reach Master.
  • Solving every problem of a div.2 contest.
  • Get a medal in the 2022 ICPC Asia HCMC Regional Contest (just 1 rank up and I'll have a bronze medal).
  • Dethroning adhoc problems.
  • Set a div 1 + 2 round.
  • Finding stable sponsors for my events.
  • Have a job.
  • Get a house.

My goals for 2023:

  • Finish university.
  • Reach Master (or Grandmaster).
  • Get a medal in ICPC 2023.
  • Set a combined round.
  • Get a job.
  • Visit another country.
  • Overcome my leftover weakness.

There may be many more things that should be on the lists, I'll add them later, as I cannot remember all of them.

Anyway, 2023 is near. Merry Christmas, and Happy New Year.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +244
  • Проголосовать: не нравится

Автор thanhchauns2, 2 года назад, По-английски

Hi Codeforces!

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

  • Start time: Aug/06/2022 17:35 (Moscow time)
  • Duration: 120 minutes.
  • Number of tasks: 6, including at least one interactive problem. Make sure to read this blog and familiarize yourself with these types of problem before the round!
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:

  1. RGB_ICPC7

  2. Xylenox

  3. 5cd

  4. Jason2022

  5. Imot

Div.1 + 2:

  1. peti1234

  2. A_G

  3. kotatsugame

  4. jiangly

  5. Rubikun

Полный текст и комментарии »

  • Проголосовать: нравится
  • +845
  • Проголосовать: не нравится

Автор thanhchauns2, история, 2 года назад, По-английски

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.

Scanning/printing the whole vector in a single std::cin/std::cout

Snippet
Usage

Scanning/printing std::pair

Snippet
Usage

Ordered set and ordered multiset

Snippet
Usage

Short declaration of 2D and 3D vectors

Snippet
Usage

Erase repeated neighbor elements

Snippet
Usage

Prime test for large numbers

Snippet

Longest Increasing Subsequence

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.

You can read more about ordered_set and ordered_multiset here: https://codeforces.net/blog/entry/11080

Thanks for reading! Hope this can help you.

A little surprise

Полный текст и комментарии »

  • Проголосовать: нравится
  • +37
  • Проголосовать: не нравится

Автор thanhchauns2, история, 2 года назад, По-английски

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:

Short link
Long link

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
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски

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.

Thanks for reading.

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • +145
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски
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

G. Trader Problem

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.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +58
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски

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
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски

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

Hope you will find this helpful ^_^ Thanks for reading.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +24
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски
  • Проголосовать: нравится
  • +301
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски

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
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски

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
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски

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

Still submitting.

Полный текст и комментарии »

  • Проголосовать: нравится
  • +52
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски

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
  • Проголосовать: не нравится

Автор thanhchauns2, история, 3 года назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • +197
  • Проголосовать: не нравится

Автор thanhchauns2, история, 4 года назад, По-английски

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.

About the map:

  • 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
  • Проголосовать: не нравится

Автор thanhchauns2, история, 4 года назад, По-английски

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
  • Проголосовать: не нравится

Автор thanhchauns2, история, 4 года назад, По-английски

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

Полный текст и комментарии »

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится