Perm hair + CF mashups
Hello! .w.
I went to the hair salon today to straighten and stick my hair to my head (idk what its called in English lmao).
The chemical process was super itchy and I had to maintain the same posture for like 20 minutes, truely inhumane…
Although after the process my hair did look pretty nice :D
In the process, I was bored, so I mind solved a mashup of 1400 to 1700 CF problems.
Suprisingly, I got them all correct after writing them at home! Im still worthy!
The problems were all pretty nice so I want to share them here (sorted by CF difficulty):
CF 1714E. Add Modulo 10
The problem is basically as follows:
For each test case, you are given an array of () integers,
you can apply an operation on any elemment,
Is it possible to make every element in the array the same by using a finite ammount of operations?
An Easy math pattern finding problem.
We can try by applying the operation on all unit digits and observe the pattern of which the unit digit changes.
Example:
9 8 6 2 4 8 6 2…
7 4 8 6 2…
After trying all of them, its easy to notice that there are two patterns:
If the unit digit is 0 or 5. After one operation the unit digit will become 0.
Else, after some ammount of operation, the unit digit will land on a 8 -> 6 -> 2 -> 4 infinite cycle.
Now we can obtain the solution:
If there is any element with 0 or 5, we apply the operation to every element once and check if they are all the same.
Else, we apply operations until they all have the same unit digit, and check if they have the same value modulo 20.
The reason its 20 is because one cycle is 8 -> 6 -> 2 -> 4, which adds up to 20.
Code (flg1 is to check if there is a element whose unit digit is 5 or 0, flg2 is check if its possible)
1 | int func(int n) { |
Time Complexity:
CF 1249C2. Good Numbers (hard version)
The problem is basically as follows:
A good number is one that can be made by using distinct powers of 3.
For each test case, you are given a number (), output the smallest good number greater or equal to .
Honestly not sure why this question is rated 1500…
The idea is really simple: Maintain an array , where .
You want to find the one that is greater or equal to , and from large to small greedily remove powers of 3 if possible.
Code
1 | void solve() { |
Time Complexity:
CF 1081B. Farewell Party
The problem is basically as follows:
Given an array, each belongs to some group. denotes how many people are in different groups then , check if theres a valid grouping that can satisfy the array’s constraints.
First, lets think about what actually means:
denotes how many people are in different groups then .
Can be changed to:
denotes how many people are in the same group as .
Although it doesn’t seem much, we can actually use this knowledge to our advantage:
This means that for a possible combination, there must be people whose value in the array is !
Further more, there might be multiple groups with the same amount of people in it.
So we can change our previous conclusion to there must be a multiple of people whose value in the array is !
After knowing this, we just need to assign groups to each person and AC this question :D
1 | void solve() { |
Time Complexity:
CF 1543D1. RPD and Rap Sheet (Easy Version)
The problem is basically as follows:
There is a password between to (). You can guess the password () times.
After each failed guess , the password will become where ( denotes binary XOR)
The problem statement actually gave me a big hint:
Password between to and guess the password () times.
Try all passwords from 0 to n - 1!
Now, the problem is that the password changes after each failed attempt. How would we solve this?
Lets observe the encoding function of the password:
(Because )
Denote the password for step as , for a failed query , the password becomes = !
Thus if we also encode our query with , the encoded value for is the same as the original to query !
Code
1 | void solve() { |
Time Complexity:
[3:09AM]
Im like also super dizzy and kinda drunk now lol, first time bar experience lets gooo!
I drank a long island ice tea, gin tonic, a few shots of whiskey and some mixed stuff.
Honesty im suprised that I have a decent alcohol tolerance, but still, drink safely!
