DIU Unlock the Algorithm Programming Contest Fall-24 [Preliminary - B Slot]
DIU Unlock the Algorithm Programming Contest Fall-24 [Preliminary - B Slot]
https://toph.co/c/diu-unlock-the-algorithm-fall-24-preliminary-b
Schedule
The contest will run for 3h0m0s.
Authors
The authors of this contest are diuacm, iffatul_anon, and kazi_amir.
Rules
This contest is formatted as per the official rules of ICPC Regional Programming
Contests.
You can use Bash 5.2, Brainf*ck, C# Mono 6.0, C++17 GCC 13.2, C++20 Clang 16.0, C+
+20 GCC 13.2, C++23 GCC 13.2, C11 GCC 13.2, C17 GCC 13.2, C23 GCC 13.2, Common
Lisp SBCL 2.0, D8 11.8, Erlang 22.3, Free Pascal 3.0, Go 1.22, Grep 3.7, Haskell 8.6, Java
1.8, Kotlin 1.9, Kotlin 2.0, Lua 5.4, Node.js 10.16, Perl 5.30, PHP 8.3, PyPy 7.3 (3.10),
Python 3.12, Ruby 3.2, Rust 1.57, Swift 5.3, and Whitespace in this contest.
Notes
There are 8 challenges in this contest.
If you find any discrepencies between the printed copy and the problem statements in
Toph Arena, please rely on the later.
By 20112011
2011, six-year-old Kiyan was in primary school, but it wasn’t books that fascinated
him; it was the old, clunky computer his father had bought with hard-earned money.
Kiyan spent hours exploring its secrets, his small fingers dancing across the keyboard.
In 20162016
2016, after finishing primary school, Kiyan joined a programming academy. While his
peers struggled with code, Kiyan treated algorithms like puzzles, cracking them
effortlessly. His teachers called him a prodigy.
By 20222022
2022, Kiyan was admitted to Daffodil International University. There, he joined the
prestigious DIU-ACM community, diving into the high-pressure world of competitive
programming. Now, in20242024
2024, Kiyan is not just a programmer—he’s a rising star
representing DIU-ACM. He is just Insane.
Now, your task is to print the specific year in which Kiyan joined the programming
academy.
Input
There is no input in this problem.
Output
Print the year in which Kiyan joined the programming academy.
Your team quickly realizes that solving this puzzle efficiently is crucial to uncover the
treasure and secure the top spot in the competition. Can you determine whether the
k−thk-
k − th occurrence of the location exists in the map? If it does, can you find its
th
position? −1-1a −1, signaling that the
If it doesn’t, the team must report back with
treasure hunt ends in failure.
The stakes are high, and time is running out. The team turns to you, the programming
wizard, to crack the puzzle. Will you rise to the challenge?
Input
1. The first line contains an integer nn
n — the number of elements in the array.
2. The second line contains
nnn integers — the elements of the AA A[i]A[i]A[i]
array A(
represents the ID of the ii−thi-
− th location).
th
3. The third line contains two integersxx
x (the location ID) andkk
k (the occurrence to
find).
Output
Print a single integer:
• The 1
1−basedindex1-
− based
based\
index k−thk-
of the k − th occurrence of x, or
\ th
• −1-1
−1 ifindex k−thk-
the k − th occurrence does not exist.
th
Constraints:
11≤n≤5001
≤ n ≤ 500
≤ ≤ A[i], x ≤ 103
11≤A[i],x≤1031
n
≤≤ k ≤ 103
11≤k≤1031
A[i],x
≤
500
≤
k≤
10^3
The problem requires identifying whether there exists a pair of scores such that their
product is divisible by a given numberKK
K . This means you must determine if there are
any two elements A[i]A[i]
A[i] and A[j]A[j] i=
j in the array such that:
A[j] where i≠ji≠j
(A[i]×A[j])%K=0(A[i]
(A[i] × A[j]) % K = 0
×
Your
A[j])team must decide quickly to either celebrate a successful "pair match" or accept
that no such pair exists.
\hspace{0.1cm}
\
Input
%
\hspace{0.1cm}
K 1. The first line contains two integers N and K, where:
=
◦ N is the number of scores in the array.
0
◦ K is the divisor to check the product against.
◦2
2≤N≤2 103 , 11≤K≤1
≤ N ≤ 10310^3 109
≤ K ≤ 10910^9
\le \le
2. The second line contains N space-separated integers, the scores in the array A,
N K
where:\le \le
◦0
0≤A[i]≤0 105 .
≤ A[i] ≤10510^5
≤A[i]≤
Output
1. Print YES if there exists at least one pair of indices(i,j)
(i, j), wherei≠ji\neq
i=
j such that
(A[i]×A[j])%K=0(A[i]
(A[i] × A[j]) % K = 0 (i, j
× j)
2. Otherwise, print NO.
A[j])
\hspace{0.1cm}
Samples
\
%
Input\hspace{0.1cm} Output
5 2 K YES
1 2 3=4 5
0
Explanation:
Input Output
2 10 YES
10 10
Input Output
2 9 NO
2 3
Input Output
5 32 -1
1 2 4 8 16
The scroll is filled with magical numbers, arranged in a sorted sequence and each one
representing an essential clue to the treasure’s location. However, the scroll is not a
simple map. The numbers repeat in patterns, and the key to unlocking the treasure lies
in finding the first and last appearance of certain numbers within the array. Only by
knowing where each number occurs can the adventurers proceed to the next clue.
As an adventurer entrusted with this critical task, you must assist your team by
uncovering the distance between the first and last appearances of the numbers. Your
goal is to help the team navigate through the scroll’s many mysteries and bring them
closer to the treasure. But beware, time is running out, and the secrets of the kingdom
may soon be lost forever.
Input
The first line contains two integersNN Q (1 ≤ N , Q ≤ 105 ) — the size of the
N andQ(1≤N,Q≤105)Q\hspace{0.2cm}
array AA (1
A and the number of queries, respectively.
\le
The second line containsNN
N integers representing
N, A(1≤A[i]≤109)A\hspace{0.2c
the sorted array A (1 ≤ A[i] ≤
109 ) (the enchanted scroll). Q (1
\le \le
The next QQ X (1 ≤ X ≤ 109 ) — a A[i]
Q lines each contain an integer X(1≤X≤109)X\hspace{0.2cm}magical number for
10^5)
which the distance between the first and (1
last occurrence must be calculated.
\le
\le 10^9)
X
Output
\le
For each query, output a single integer: 10^9)
• If the number XX
X appears in the array, print the distance between the index of its
last and first occurrence.
• If the number XX
X does not appear in the array, print −1-1
−1, signaling that the clue is
no longer relevant.
You are given an array a of size n, where every element of the array a[i] represents
Billu’s i-th weekly exam marks.
Input
The first line will be a single integer N indicating the number of weekly exams. The
following N lines will contain an Integer a[i] which represents the number of i-th
weekly exams.
Constraints:
≤ N ≤ 105
11≤N≤1051\le
≤ A[i] ≤ 106
N\le10^5
11≤A[i]≤1061\le
A[i]
\le10^6
Output
You have to print a integerKK
K , the minimum number of exam marks he must remove
so that his parents will be happy.
Samples
Input Output
4 1
1 2 3 1
Rules
• nn
n is the size of the array.
• You can perform at most kk
k operations on the array.
• For each a[i]a[i]
a[i] that matches b[i]b[i]
b[i] after the operations, you receive c[i]c[i]
c[i] coins.
Input
The first line contains a single integer t(1≤t≤100)t
t(1 ≤ t ≤ 100) — the number of test cases.
For each test case: (1
≤
• The first line contains two integers:
t n(1 ≤ n ≤ 103 )
n(1≤n≤103)n
the size of the array:
and the maximum number of operations:
≤ k(0 ≤ k ≤ 106 )(1
k(0≤k≤106)k .
100) (0 ≤
• The second line contains n integers representing the target valuesb(1≤b[i]≤103)b
b(1 ≤
≤ n
3 (1
b[i] ≤ 10 ). k ≤
≤
• The third line contains n integers representing 10^3) ≤
c(1≤c[i]≤106)c
b[i]c(1 ≤
the number of coin
6 10^6) (1
c[i] ≤ 10 ) you will earn for each match.
≤
Samples
Input Output
4 9
4 4 0
1 7 5 2 30
2 6 5 2 167
3 0
3 5 2
5 4 7
5 9
5 2 5 6 3
5 9 1 9 7
6 14
11 4 6 2 8 16
43 45 9 41 15 38
The riddle comes with a dire warning: "If the treasure is hidden beyond the occurrence, it
is lost forever!"
Your team quickly realizes that solving this puzzle efficiently is crucial to uncover the
treasure and secure the top spot in the competition. Can you determine whether the
number XX
X exists in the map? If it does print “YES” otherwise print “NO”.
Input
The first line contains an integer N (1≤N≤500)N\
(1 ≤ N ≤ 500) — the number of elements in the
array. (1\le
N\le
The second line containsNN N integers A(1≤A[i]≤103).A\hspace{0.2c
500) — the elements of the array A (1 ≤ A[i] ≤
3 (1
10 ).
\le
The third line contains single integers X.X.
X. A[i]
\le
Output 10^3).
If the numberXX
X is present in the array print “YES”, otherwise print “NO”, without
quotations.
Samples
Input Output
10 YES
4 2 6 4 8 3 9 4 2 6
2