0% found this document useful (0 votes)
10 views36 pages

NGPC 2022 Analysis

The National Girls’ Programming Contest 2022 featured 10 problems with 104 teams participating. Key problems included creating strong passwords, optimizing mathematical expressions, and calculating probabilities in game scenarios. Solutions varied in complexity, with some problems being solved by nearly all teams while others had significantly fewer successful attempts.

Uploaded by

srijon rahat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views36 pages

NGPC 2022 Analysis

The National Girls’ Programming Contest 2022 featured 10 problems with 104 teams participating. Key problems included creating strong passwords, optimizing mathematical expressions, and calculating probabilities in game scenarios. Solutions varied in complexity, with some problems being solved by nearly all teams while others had significantly fewer successful attempts.

Uploaded by

srijon rahat
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 36

National Girls’ Programming Contest 2022

Judge Notes

February 25, 2023


Stat C G E I B J D H A F Contrib

Statistics

10 problems.
104 teams.

Summary NGPC 2022 1 / 35


Stat C G E I B J D H A F Contrib

C. Strong Passwords

Author: Rafid Bin Mostofa

Number of Teams Solved: 100


Number of Teams Tried: 103

Abridged Problem Statement


Suggest a standard strong password with certain requirements.

Summary NGPC 2022 2 / 35


Stat C G E I B J D H A F Contrib

Solution

One such solution is Mitu1997@qt!

Summary NGPC 2022 3 / 35


Stat C G E I B J D H A F Contrib

G. Alligator Sky

Author: Iftekhar Hakim Kaowsar

Number of Teams Solved: 71


Number of Teams Tried: 93

Abridged Problem Statement


Maximum value of x + y such that x · a + y · b = n, a + b ≥ k and
0 ≤ (x − y ) ≤ 1.

Summary NGPC 2022 4 / 35


Stat C G E I B J D H A F Contrib

Solution

Optimal to choose a, b such that a + b = k.

(
⌊n/k⌋ · 2 if k divides n
Result =
⌊n/k⌋ · 2 + 1 otherwise

Summary NGPC 2022 5 / 35


Stat C G E I B J D H A F Contrib

Solution (contd)

Handle k = 1 separately, result is n.

Summary NGPC 2022 6 / 35


Stat C G E I B J D H A F Contrib

E. Shortest Path, Yet Again

Author: Sabbir Rahman Abir

Number of Teams Solved: 38


Number of Teams Tried: 60

Abridged Problem Statement


Given n, m, k, create a n × m grid with start cell, end cell and
obstacles such that shortest path between start and end cell is k.

Summary NGPC 2022 7 / 35


Stat C G E I B J D H A F Contrib

Solution (1/2)

Just make a zigzag path with start cell at top left.

Then traverse this path for k cells and put the end cell!

Summary NGPC 2022 8 / 35


Stat C G E I B J D H A F Contrib

Solution (2/2)

nm
This works as 2 ≤ k ≤ 2 and in the contsruction, more than half
cells are free.

The traversal can be done via a BFS or just a while loop with
some if else.

Summary NGPC 2022 9 / 35


Stat C G E I B J D H A F Contrib

I. Farewell Gift for Messi

Author: Md. Shariful Islam

Number of Teams Solved: 11


Number of Teams Tried: 16

Abridged Problem Statement


Given n, p, x, y , find number of possible arrays with length n with
integer values in [0, 2p ) such that bitwise OR of the array is x and
bitwise AND of the array is y .

Summary NGPC 2022 10 / 35


Stat C G E I B J D H A F Contrib

Solution

Consider the number of ways for each of the p bits separately.

For a particular bit,


If both OR and AND have same value, we must assign that
value for every index in the array.
If AND has 1 but OR has 0, there is no such array, hence
answer will be 0.
If AND has 0 but OR has 1, the number of ways is (2n − 2)
(excluding all 0’s and all 1’s).

Summary NGPC 2022 11 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

So, the answer is 0 if there is some bit where AND is 1 but OR is 0.

Otherwise the answer is (2n − 2)x , where x is the number of bits


where AND is 1 but OR is 0.

Summary NGPC 2022 12 / 35


Stat C G E I B J D H A F Contrib

B. Angels and Demons

Author: Tariq Bin Salam

Number of Teams Solved: 3


Number of Teams Tried: 16

Abridged Problem Statement


Given Q range addition/subtraction updates, what is the initial
minimum value, such that applying these updates sequentially does
not make the running sum 0 or lower at any point?

Summary NGPC 2022 13 / 35


Stat C G E I B J D H A F Contrib

Solution

Observation: It is possible to do a binary search on the result.


How to check if you can survive with initial health H?
Sort all intervals according to S and simulate the updates
from checkpoint 1 to N with health H and see if you survived
Complexity: O(Q log(H)) where H is the maximum possible
initial health.

Summary NGPC 2022 14 / 35


Stat C G E I B J D H A F Contrib

J. Wizard Duel

Author: Rafid Bin Mostofa

Number of Teams Solved: 2


Number of Teams Tried: 10

Abridged Problem Statement


Given a few ratios of unknown variables, compute ratio between
two query variables.

Summary NGPC 2022 15 / 35


Stat C G E I B J D H A F Contrib

Solution

Fractions can be chained and multiplied together to get the values


of a new fraction.
a a c z
= × × ··· ×
b c d b

Summary NGPC 2022 16 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

Consider the wizards as vertices.

Pi
For each info Pj = yx , we add two directed edges:
x
i to j with weight y
y
j to i with weight x

Summary NGPC 2022 17 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

The value of PPba is the multiplication of weights of the edges in the


path from a to b.

If there are no such paths, the outcome is unknown.

If the value equals 1, it is a draw. Otherwise, if it’s greater than 1,


it is a win and lose otherwise.

We can use DFS, BFS or DSU to traverse the graph.

Summary NGPC 2022 18 / 35


Stat C G E I B J D H A F Contrib

D. Interesting Parenthesis

Author: Mahdi Hasnat Siyam

Number of Teams Solved: 1


Number of Teams Tried: 3

Abridged Problem Statement


Count the number of parentheses sequence of length 2n, that can
be balanced by at most one swap.

Summary NGPC 2022 19 / 35


Stat C G E I B J D H A F Contrib

Solution

Consider all opening parentheses as +1, and all closing parentheses


as -1.

To check if a parentheses sequence is balanced:


Summation of the +1, -1 values equals to 0.
None of the prefix sum is less than 0.

A parenthesis sequence is interesting if all of the prefix sums are


greater than or equal to −2 and the total sum is 0.

Summary NGPC 2022 20 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

Let dp(n, c) be the number of parenthesis sequence we can


generate such that we have remaining n position left and current
prefix sum is c.
dp(0, 0) = 1
dp(0, c ̸= 0) = 0
We can compute dp(n, c) by the following:
(
dp(n − 1, c + 1) + dp(n − 1, c − 1) if c − 1 ≥ −2
dp(n, c) =
dp(n − 1, c + 1) otherwise

Summary NGPC 2022 21 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

Complexity: O(N 2 ).

There exists a faster approach using the idea of Catalan Numbers.


See OEIS series A026012.

Summary NGPC 2022 22 / 35


Stat C G E I B J D H A F Contrib

H. Plantik

Author: Kazi Md Irshad

Number of Teams Solved: 0


Number of Teams Tried: 0

Abridged Problem Statement


Calculate the probability of a team winning a penalty shootout,
given scoring probabilities of each player.

Summary NGPC 2022 23 / 35


Stat C G E I B J D H A F Contrib

Solution

The optimal shooting order is sorted in non-increasing order.


Which means the best shooter will go first and the worst will go
last. 5 best shooters already took shots.

Remaining shooting order is from 6th to 11th, then 1st to 5th.

Let us relabel the shooters (from 6th to 11th, then 1st to 5th) as
1st to 11th.

Summary NGPC 2022 24 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

Let fi be the probability that Argentina wins from the situation


when the next shooters of each team is i. Let Xi be the probability
that Argentina win after each team’s i shoots. And Yi be the
probability that the shootout continues.

If Argentina score and France miss then Argentina win.

Xi = Ai · (1 − Fi )
If both players score or miss, the shootout continues.

Yi = Ai · Fi + (1 − Ai ) · (1 − Fi )

Summary NGPC 2022 25 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

Now we can write for each i in range [1, 10]

fi = Xi + Yi · fi+1
And additionally

f11 = X11 + Y11 · f1


We need to find f1 .

Summary NGPC 2022 26 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

We can solve the equations by iteratively merging the linear


equations.

We can also solve it by algebraic manipulation.


11
P j<i
Q
(Xi · Yi )
i=1 j=1
f1 = 11
Q
1− Yi
i=1

We can also solve it by gaussian elimination.

Summary NGPC 2022 27 / 35


Stat C G E I B J D H A F Contrib

A. Half Measures

Author: Pritom Kundu

Number of Teams Solved: 0


Number of Teams Tried: 24

Abridged Problem Statement


The numbers 1, 2, · · · n are written on a board. In one operation,
you can halve any number. Find minimum sum after k operations.

Summary NGPC 2022 28 / 35


Stat C G E I B J D H A F Contrib

Solution

Observation: Its always optimal to choose the largest


number and halve it.
O(k) solution by simulation. Too slow.

Summary NGPC 2022 29 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

Multiple ways to optimize. Instead of choosing one number at


a time, we can choose an interval [l, r ] with l > r /2, and
perform all moves at once.
Keep intervals of the form (l, r , x) meaning numbers from l to
r exists exactly x times. make sure that l > r /2. Then take
the last interval, halve it and merge with existing intervals.
It can be proven that there will be at most O(log (n))
intervals leading to a O(log 2 (n)) sol.
O(log (n)) solutions exist, but even harder to implement.

Summary NGPC 2022 30 / 35


Stat C G E I B J D H A F Contrib

F. Predict The Frequency

Author: Iftekhar Hakim Kaowsar

Number of Teams Solved: 0


Number of Teams Tried: 3

Abridged Problem Statement


Given N, M, X , construct all possible array with length N with
values in [1, M] such that none of their frequency exceeds X .
Score of an array is the maximum frequency of its values. Find the
sum of score of all possible arrays.

Summary NGPC 2022 31 / 35


Stat C G E I B J D H A F Contrib

Solution

Let us define dp(n, m, x) as the number of arrays with length


n, constructed by values [1, m] and maximum frequency of its
values does not exceed x.
In the transition part, we will iterate over how many values
will get frequency x. This count will surely not exceed ⌊ xn ⌋.
Otherwise, final array size will exceed n. So, count
c = 0 · · · ⌊ xn ⌋.

Summary NGPC 2022 32 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

If we fix a value of c, we can choose c distinct values in m



c
ways.
n

We can choose c · x positions to place them in c·x ways.
(c·x)!
Placing those values in those position has (x!)c ways.

Summary NGPC 2022 33 / 35


Stat C G E I B J D H A F Contrib

Solution (contd.)

n
⌊ x ⌋   
X m n (c · x)!
dp(n, m, x) = dp(n − c · x, m − c, x − 1)
c c · x (x!)c
c=0

This may look like O(n4 ). But the number of total transition
is limited by O(nlgn). To proof this, fix n and m. For those
fixed n and m, the total transition will be
⌊ n1 ⌋ + ⌊ n2 ⌋ + ... + ⌊ nn ⌋. This is shaped by sum of harmonic
series which is nlogn.
Hence, total complexity will O(n3 logn).

Summary NGPC 2022 34 / 35


Stat C G E I B J D H A F Contrib

Contributors

Rafid Bin Mostofa, BUET


Mahdi Hasnat Siyam, BUET
Pritom Kundu, BUET
Tariq Bin Salam, BUET
Iftekhar Hakim, BUET
Shariful Islam, BUET
Apurba Saha, BUET
Sabbir Rahman Abir, BUET
Kazi Md Irshad, BUET
Shimul Sutradhar, DIU
Abu Saleh, DIU
Md. Rahat Islam, DIU

Summary NGPC 2022 35 / 35

You might also like