Code Trap Programming Contest Fall 2024 Editorial
Code Trap Programming Contest Fall 2024 Editorial
D
Programming Contest Fall 2024
Editorial
usha Hasan
E
Mahfuzur Rahman Shanto
Md. Iffatul Islam Anon
Md. Abdul Alim
Arfan Arif
Piyash Basak
Saiful Islam Ramim
Abu Naeem
Ishrak Tawsif Nirob
Aumit Hasan Bappy
Jafrin Iqbal Chowdhury
Rifa Tasfia
Arpita Paul
Tahmina Meem
Mujahidul Islam
Abdul Hye Zebon
Mazbaur Rahid
Mohammad Azam Khan
Problem Name: “The Spirit of July: A Triumph of Student Unity”
Tag: Giveaway
Problem Setter : Saiful Islam Ramim
Tester: Ishrak Tawsif
remaining_mangos=total_mangos−stolen_mangos
Code:
Problem Name: “Alphabet Battle”
Tag: Conditional
Problem Setter: Eusha Hasan
Tester: Aumit Hasan
his problem revolves around a basic comparison using if-else conditions. Two characters are
T
provided, and the task is to determine which character appears earlier in the English alphabet.
Then do basic if else operation according to the problem statement and print the specific
sentence with adding new line at the end of the line.
Code:
Code:
Problem Name: “Spiral Triangle”
Tag: Geometry
Problem Setter: Md. Abdul Alim
ester: Md. Iffatul Islam Anon, Mahfuzur Rahman Shanto, Ishrak Tawsif Nirob
T
ditorial:The hypotenuse of the first triangle willbe root 2, the hypotenuse of the second
E
triangle will be root 3.
This will give a pattern that the hypotenuse of the Nth triangle will be root (N + 1)
Problem Understanding
e are given a sequence of right-angled triangles, where the hypotenuse follows a pattern.
W
Specifically:
From the given information, the hypotenuse of the Nth triangle follows the pattern:
y observing the pattern and applying the Pythagorean theorem, we have derived that the
B
hypotenuse of the Nth triangle is given by:
In this problem participants are assigned to projects based on the Fibonacci sequence where
the number of participants in a project is the sum of the participants in the two preceding
projects. The first two projects in each category start with one participant each.
or example:
F
Project 1: 1 participant
Project 2: 1 participant (0 + 1)
Project 3: 2 participants (1 + 1)
Project 4: 3 participants (1 + 2)
Project 5: 5 participants (2 + 3)
and so on…
Total sum of the participants for all project slots in both categories is the final answer.
xplanation:
E
For, W = 7 and M = 6
ime Complexity:
T
Since we perform a binary search on the value of MMM, the time complexity for the binary
search isO(logM). For each possible MMM, we checkall T-scanned data. Therefore, the total
time complexity isO(T log M).
Code:
Problem Name: “Battle Of Archers”
Tag: Segment Tree
Problem Setter:Piyash Basak
ester: Mujahidul Islam, Saiful Islam Ramim, Anupam Islam Akib
T
1. Boost Command: Amplify attack power starting at position P with an initial power X,
decaying linearly leftward.
2. Attack Command: Compute the total attack power of archers in a specified range [a, b].
The challenge is to handle these commands efficiently for large constraints (N , Q ≤ 200,000).
Approach:
Complexity:
● Build:O(N).
● Update/Query:O(logN).
Code:
Problem Name: “Escape the Trap”
Tag: Number theory, Greedy
Problem Setter: Md. Abdul Alim
ester: Mahfuzur Rahman Shanto, Ishrak Tawsif Nirob, Piyash Basak
T
Editorial:
Problem Understanding
2
A = 2𝑥 + 11x
x = ( x mod 7 + 7 ) mod 7
Code Explanation
tep 2: Run a loop from D to N and identify whether the current value is prime or not. If
S
the value is prime then check whether Tarita has crossed minimum X distance from the
last point she has drank water. If yes, then she will drink water and the last point of
drinking water will be the current position.
Sample:
Input: 10 2 5
Output: 1
Explanation:
arita has to run a total distance of 10 meters. The prime numbers less than or equal to
T
10 are 2, 3, 5, and 7, which represent potential hydration points. However, she can only
drink water if she has covered at least 5 meters since the last time she hydrated.
● A t 2 meters, Tarita encounters a hydration point, but since she has not covered
the required 5 meters yet, she cannot drink water.
● At 3 meters, another hydration point is encountered. Again, she cannot drink
water because she has not reached the 5-meter minimum.
● At 5 meters, Tarita encounters a hydration point and has now covered the
required minimum of 5 meters. She drinks water and continues running.
● At 7 meters, she finds another hydration point, but the distance covered since her
last hydration point is only 2 meters (from 5 to 7), which is less than the required
5 meters. Therefore, she does not drink water.
● No more hydration points are encountered up to 10 meters.
Thus, in this 10-meter marathon, Tarita gets a chance to hydrate only once.
Code:
Problem Name: “Pillow Passing”
Tag: Implementation, Math
Problem Setter: Md. Iffatul Islam Anon
Tester: Piyash Basak, Ishrak Tawsif Nirob
Initialization
a
● [] is an array that holds the players, numbered sequentially from 1 to n.
● The variable j = 0 represents the current position of the pillow holder at the start
of the game.
Game Simulation
● T he game is simulated over n-1 rounds since one player is eliminated in each
round.
● For each round:
○ The formula (j + b[i] - 1) % (n - i) is used to determine the index of the
player who gets eliminated:
■ j is the current index of the pillow holder.
■ b[i] is the number of seconds for which the pillow is passed in the
current round.
■ (n - i) represents the number of players still in the game.
○ After identifying the player to be eliminated, the remaining players in the
array are shifted to fill the gap left by the removed player, effectively
reducing the size of the circle.
Final Output
● A
fter all eliminations, the only player left in the array will be at index a[0]. This
player is declared the winner.
Time Complexity
● O(n²):
○ In each round, we shift the remaining players in the array, which takes
O(n) time in the worst case.
○ There are n-1 rounds, so the overall time complexity is O(n²).
Space Complexity
● O(n):
○ T he space complexity is dominated by the array a[], which stores the
players, resulting in O(n) space usage.
Code :
Problem Name: “Voldemort’s Forbidden Words”
Tag: String Processing
Problem Setter: Abdul Hai Jibon
Tester: Rifa Tasnia, Aumit Hasan, Mujahidul Islam
Problem Understanding:
he problem requires determining how many times each forbidden word can be fully formed
T
using the given message while consuming characters sequentially. Once a word is formed, its
characters are no longer available for subsequent words.
Key Idea:
Now, 'b' is also completely used up, so "cab" can no longer be formed again.
Final Output
Complexity Analysis
C
● ounting characters in a string:O(|S|)
● Checking formations for each word:O(N * |W|)
● Overall complexity:O(|S| + N * |W|), which is efficientgiven the constraints.
Implementation Details
Key Insight
Approach Explanation
Solution
o solve the problem efficiently, we use the contribution technique. Instead of calculating the
T
MEX for every possible subarray individually, we decompose the problem into distinct cases
based on the properties of the array's elements and their positions.
y combining all these cases, we can compute the total MEX chaos by considering the
B
contribution of different types of subarrays, without explicitly iterating over all possible
subarrays.
Code: