A Combined
A Combined
Problem Statement
from Day Ai , where Day 1 is the launch day, and did not log in for the other days. In other
days.
For each integer k such that 1 ≤ k ≤ N , find the number of days on which exactly k players
logged in.
Constraints
1 ≤ N ≤ 2 × 105
1 ≤ Ai ≤ 109
1 ≤ Bi ≤ 109
Input
N
A1 B1
A2 B2
:
AN BN
Output
D1 D2 ⋯ DN
-
Unsolved Problem Practice Sep 01, 2023
Here, Di denotes the number of days on which exactly k players logged in.
Sample 1
Input Output
3 2 2 0
1 2
2 3
3 1
The first player logged in on Day 1, 2, the second player logged in on Day 2, 3, 4, and the
third player logged in on Day 3 only.
Thus, we can see that Day 1, 4 had 1 player logged in, Day 2, 3 had 2 players logged in, and
the other days had no players logged in.
The answer is: there were 2 days with exactly 1 player logged in, 2 days with exactly 2
players logged in, and 0 days with exactly 3 players logged in.
Sample 2
Input Output
2 0 1000000000
1000000000 1000000000
1000000000 1000000000
There may be two or more players who logged in during the same period.
-
Unsolved Problem Practice Sep 01, 2023
In your programming class, you are given an assignment to analyze an integer array using a
sliding window algorithm. Specifically, given N integers w1 , … , wN and some constant C ,
the sliding window algorithm maintains start and end indices s and e such that
initially s = e = 1;
as long as s ≤ N:
else increment e.
During the execution of this algorithm, each distinct pair of indices (s, e) defines a window.
An element wi belongs to the window defined by (s, e) if s
≤ i ≤ e. Notice that if s > e, the
window is empty.
Consider the first sample input below. The windows appearing during the execution of the
algorithm are defined by (1, 1), (1, 2), (1, 3), (2, 3), (3, 3), (3, 4), (4, 4), (5, 4), (5, 5), and
(6, 5).
For each element wi , determine how many different windows it belongs to during the
Input
The first line of input contains two integers N (1 ≤ N ≤ 100 000), which is the number of
elements, and C (1 ≤ C ≤ 1 000 000), which is the sliding window constant.
Output
For each element, in order, display the number of different windows it belongs to during the
execution of the algorithm.
Sample 1
-
Unsolved Problem Practice Sep 01, 2023
Input Output
5 3 3
1 1 1 2 2 3
4
2
1
Sample 2
Input Output
5 10 4
1 2 3 4 5 4
4
5
2
-
Unsolved Problem Practice Sep 01, 2023
RK has received a homework assignment to compute the greatest common divisor of the
two positive integers A and B. Since the numbers are quite large, the professor provided him
with N smaller integers whose product is A, and M integers with product B.
RK would like to verify his result, so he has asked you to write a program to solve his
problem. If the result is more than 9 digits long, output only the last 9 digits.
Input
The first line of input contains the positive integer N (1 <= N <= 1000).
The second line of input contains N space-separated positive integers less than 10^9, whose
product is the number A.
The third line of input contains the positive integer M (1 <= M <= 1000).
The fourth line of input contains M space-separated positive integers less than 10^9, whose
product is the number B.
Output
The first and only line of output must contain the greatest common divisor of numbers A
and B. If the result is more than 9 digits long, output only the last (least significant) 9 digits.
Example
Input
3
2 3 5
2
4 5
Output
10
-
Unsolved Problem Practice Sep 01, 2023
Input
3
358572 83391967 82
3
50229961 1091444 8863
Output
000012028
First sample description: The greatest common divisor of numbers A = 30 and B = 20 equals
10.
-
Unsolved Problem Practice Sep 01, 2023
Farmer John has N cows that need to be milked (1 <= N <= 10,000), each of which takes only
one unit of time to milk.
Being impatient animals, some cows will refuse to be milked if Farmer John waits too long
to milk them. More specifically, cow i produces g_i gallons of milk (1 <= g_i <= 1000), but
only if she is milked before a deadline at time d_i (1 <= d_i <= 10,000). Time starts at t=0,
so at most x total cows can be milked prior to a deadline at time t=x.
Please help Farmer John determine the maximum amount of milk that he can obtain if he
milks the cows optimally.
Input
Output
A single numbers denotes the maximum number of gallons of milk Farmer John can obtain.
Sample
Input Output
4 25
10 3
7 5
8 1
2 1
Explanation
There are 4 cows. The first produces 10 gallons of milk if milked by time 3, and so on.
-
Unsolved Problem Practice Sep 01, 2023
Farmer John milks cow 3 first, giving up on cow 4 since she cannot be milked by her
deadline due to the conflict with cow 3. Farmer John then milks cows 1 and 2.
***
Nông dân John có N con bò, để vắt sữa một con bò cần 1 đơn vị thời gian.
Vốn là loài vật lười, những con bò sẽ không chịu để vắt sữa nếu John bắt chúng chờ quá lâu. Cụ thể, con bò i
cho g_i gallon sữa, nhưng chỉ khi nó được vắt sữa trước thời gian d_i. Thời gian bắt đầu ở T = 0, nên có tối
Hãy giúp nông dân John tính lượng sữa tối đa mà ông có thể vắt được nếu như ông chọn được cách vắt hiệu
quả nhất.
Input :
Output :
Giới hạn :
- 1 ≤ n ≤ 10000
- 1 ≤ g_i ≤ 1000
- 1 ≤ d_i ≤ 10000
Ví dụ :
Input :
-
Unsolved Problem Practice Sep 01, 2023
10 3
75
81
21
Output :
25
Giải thích : John vắt sữa con bò 3, sau đó đến con 1 rồi con 2.
-
Unsolved Problem Practice Sep 01, 2023
Given an integer N (0 <= N < 107), find the smallest positive integer M (M > 0) such that the
product of digits of M equals N.
Input
The first line of input is T (the total number of test cases), followed by T (T < 10001) lines,
each containing an integer N.
Output
For each integer N, output in a separate line the integer M, or -1 (if encoding is not
possible).
Example
Input Output
3 38
24 5
5 -1
11
-
Unsolved Problem Practice Sep 01, 2023
Bob is an aspiring archaeologist. He has found n ancient scrolls, each with an unusual sum
written on it. The sum on the i-th scroll reads as
Bob thinks that precise values of these sums encode the location of Aldoredo, the not-so-
famous city of gold. Help him calculate the values of the sums!
Input
5
The first line contains a single integer n, the number of scrolls (1 ≤ n ≤ 10 ). The i-th of the
next n lines contains two space-separated integer numbers li and ri, the description of the
Output
Output n lines: in the i-th line output the value of the sum written on the i-th scroll. Your
answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.
Sample 1
Input Output
3 0.666666666667
1 2 0.016424751719
34 76 0.050000000000
4 4
-
Unsolved Problem Practice Sep 01, 2023
As part of his daily job, Chef has to solve problems involving sets. Till now, Chef has been
using inefficient methods to solve his set related problem, wasting a lot of his precious
time. He has agreed to pay you a lot of money for solving the following problem for him
efficiently.
1. Add a number to the set (if this number is NOT already present in the set).
2. Erase a number from the set (if this number exists in the set).
Then, he needs to find the sum of all elements of the set after performing these Q
queries. Your job is to find this sum for him quickly.
Input
The first line of input contains four integers — Q, S1, A, B. S1 is the first number in the
first operation, otherwise the second type, and in both of them the integer you have to
add/delete equals [Si / 2], where [] is the greatest integer (or floor) function.
Note: In this problem, the time limit is very tight. Using built-in data structures, such
as set/unordered_set in C++ or TreeSet/HashSet in Java, may lead to a Time Limit
Exceed verdict.
Output
Output a single line containing a single integer — sum of elements in the set after Q
queries.
-
Unsolved Problem Practice Sep 01, 2023
Constraints
1 ≤ Q ≤ 107
1 ≤ S1, A, B ≤ 109
Example
Input:
5 1 1 1
Output:
3
Input:
10000000 777777777 777777777 777777777
Output:
5362358669068782
Explanation:
-
Unsolved Problem Practice Sep 01, 2023
There is a street of length x whose positions are numbered 0, 1, … , x. Initially there are no
traffic lights, but n sets of traffic lights are added to the street one after another.
Your task is to calculate the length of the longest passage without traffic lights after each
addition.
Input
The first input line contains two integers x and n: the length of the street and the number of sets
of traffic lights.
Then, the next line contains n integers p1 , p2 , … , pn : the position of each set of traffic lights.
Output
Print the length of the longest passage without traffic lights after each addition.
Constraints
1 ≤ x ≤ 109
1 ≤ n ≤ 2 ⋅ 105
0 < pi < x
Example
Input Output
8 3 5 3 3
3 6 2
-
Unsolved Problem Practice Sep 01, 2023
Chef has a tasty ingredient ― an integer K . He defines a tasty matrix A with N rows
(numbered 1 through N ) and M columns (numbered 1 through M ) as Ai,j = K + i + j for
each valid i, j .
Currently, Chef is busy in the kitchen making this tasty matrix. Help him find the bitwise
XOR of all elements of this matrix.
Input
The first line of the input contains a single integer T denoting the number of test
cases. The description of T test cases follows.
The first and only line of each test case contains three space-separated integers N , M
and K .
Output
For each test case, print a single line containing one integer ― the bitwise XOR of all
elements of the tasty matrix with the given dimensions made with the given special
ingredient.
Constraints
1 ≤ T ≤ 105
1 ≤ N , M ≤ 2 ⋅ 106
1 ≤ K ≤ 109
the sum of N over all test cases does not exceed 2 ⋅ 106
the sum of M over all test cases does not exceed 2 ⋅ 106
Sample 1
-
Unsolved Problem Practice Sep 01, 2023
Input Output
2 14
2 2 5 5
2 3 7
5+1+1 5+1+2 7 8
A=( )=( ).
5+2+1 5+2+2 8 9
-
Unsolved Problem Practice Sep 01, 2023
Chef has a secret integer. The only information you have is that it has an odd number of
factors and that it lies between 1 and 106 inclusive.
You have been challenged by Chef to find his number. You may make up to 2, 000 guesses
(queries). Whenever you guess Chef's number, he only tells you if you guessed correctly or
not. Can you find Chef's number?
Interaction
First, you should read a line containing a single integer T ― the number of test cases.
The description of interaction for T test cases follows.
For each test case, you should start by asking queries.
To ask a query, you should print a line containing an integer between 1 and 106
inclusive ― your guess.
Then, you should read a line containing a single integer: 1 if you correctly
guessed Chef's secret number, 0 if your guess was incorrect or −1 if your guess is
invalid (in particular, smaller than 1 or greater than 106 ) or you have asked more
than 2, 000 queries.
As soon as you have correctly guessed Chef's secret number, you should stop asking
queries and continue solving the remaining test cases.
If you read −1, you must immediately terminate your program to receive a Wrong Answer
verdict. Otherwise, you may receive any verdict. Don't forget to flush the output after
printing each line! You can read more about interactive problems here.
Constraints
1 ≤ T ≤ 100
Chef's secret number lies between 1 and 106 inclusive
Chef's secret number has an odd number of factors
-
Unsolved Problem Practice Sep 01, 2023
Interaction
1 Grader You
2 1
3 232
4 0
5 92739
6 0
7 100
8 1
Explanation
Example case 1:
You ask Chef if 232 is his secret number. Chef replies with 0, so it is not.
You ask Chef if 92, 739 is his secret number. Chef replies with 0, so it is not.
You ask Chef if 100 is his secret number. Chef replies with 1, so this is indeed his secret
number.
-
Unsolved Problem Practice Sep 01, 2023
Mike received an array a of length n as a birthday present and decided to test how pretty it
is.
An array would pass the i-th prettiness test if there is a way to get an array with a sum of
elements totaling si , using some number (possibly zero) of slicing operations.
max(array)+min(array)
assume mid = ⌊
2
⌋, where max and min — are functions that
find the maximum and the minimum array elements. In other words, mid is the sum
of the maximum and the minimum element of array divided by 2 rounded down.
Then the array is split into two parts left and right . The left array contains all
elements which are less than or equal mid, and the right array contains all elements
which are greater than mid. Elements in left and right keep their relative order from
array.
During the third step we choose which of the left and right arrays we want to keep.
The chosen array replaces the current one and the other is permanently discarded.
You need to help Mike find out the results of q prettiness tests.
Note that you test the prettiness of the array a, so you start each prettiness test with the
primordial (initial) array a. Thus, the first slice (if required) is always performed on the
array a.
Input
-
Unsolved Problem Practice Sep 01, 2023
Each test contains one or more test cases. The first line contains the number of test cases t (
1 ≤ t ≤ 100).
The first line of each test case contains two integers n and q (1 — the length
5
≤ n, q ≤ 10 )
Next q lines of each test case contain a single integer si — the sum of
9
(1 ≤ si ≤ 10 )
It is guaranteed that the sum of n and the sum of q does not exceed 105 (∑ n, ∑ q 5
≤ 10 ).
Output
Print q lines, each containing either a "Yes" if the corresponding prettiness test is passed
and "No" in the opposite case.
Sample 1
Input Output
2 Yes
5 5 No
1 2 3 4 5 Yes
1 No
8 Yes
9 No
12 Yes
6 No
5 5 Yes
3 1 3 1 3 Yes
1
2
3
9
11
Note
-
Unsolved Problem Practice Sep 01, 2023
1+5
1.1 a = [1, 2, 3, 4, 5], mid =
2
= 3 , left = [1, 2, 3] , right = [4, 5] . We choose to
keep the left array.
1+3
1.2 a = [1, 2, 3], mid =
2
= 2 , left = [1, 2], right = [3]. We choose to keep the
left array.
1+2
1.3 a = [1, 2] , mid =
2
= 1 , left = [1], right = [2]. We choose to keep the left
array with the sum equalling 1.
2. It can be demonstrated that an array with the sum s2 = 8 is impossible to generate.
3. An array with the sum s3 = 9 can be generated in the following way:
2.1 a = [3, 1, 3, 1, 3], mid = = 2 , left = [1, 1], right = [3, 3, 3] . We choose to
1+3
1+3
4.1 a = [3, 1, 3, 1, 3], mid =
2
= 2 , left = [1, 1], right = [3, 3, 3] . We choose to
keep the right array with the sum equalling 9.
5. We can get an array with the sum s5 = 11 with zero slicing operations, because array
sum is equal to 11.
-
Unsolved Problem Practice Sep 01, 2023
Theofanis has a string s1 s2 … sn and a character c. He wants to make all characters of the
string equal to c using the minimum number of operations.
In one operation he can choose a number x (1 ≤ x ≤ n) and for every position i, where i is
not divisible by x , replace si with c.
Find the minimum number of operations required to make all the characters equal to c and
the x -s that he should use in his operations.
Input
The first line contains a single integer t (1 ) — the number of test cases.
4
≤ t ≤ 10
The first line of each test case contains the integer n (3 ) and a lowercase
5
≤ n ≤ 3 ⋅ 10
Latin letter c — the length of the string s and the character the resulting string should
consist of.
The second line of each test case contains a string s of lowercase Latin letters — the initial
string.
It is guaranteed that the sum of n over all test cases does not exceed 3 ⋅ 10 .
5
Output
For each test case, firstly print one integer m — the minimum number of operations
required to make all the characters equal to c.
It can be proved that under given constraints, an answer always exists. If there are multiple
answers, print any.
Sample 1
-
Unsolved Problem Practice Sep 01, 2023
Input Output
3 0
4 a 1
aaaa 2
4 a 2
baaa 2 3
4 b
bzyx
Note
1. x1 = 2: we choose all positions that are not divisible by 2 and replace them, i. e. bzyx
→ bzbx;
2. x2 = 3: we choose all positions that are not divisible by 3 and replace them, i. e. bzbx
→ bbbb.
-
Unsolved Problem Practice Sep 01, 2023
Problem P. Datatypes
Time limit 2000 ms
Mem limit 262144 kB
Since his older brother is such a good programmer, his biggest dream is to outshine him.
Tuftuf is a student at the German University in Cairo (GUC) where he learns to write
programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned
integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer
datatypes' sizes. The second line contains a single-space-separated list of n integers
(1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Sample 1
Input Output
3 NO
64 16 32
-
Unsolved Problem Practice Sep 01, 2023
Sample 2
Input Output
4 YES
4 2 1 3
Note
-
Unsolved Problem Practice Sep 01, 2023
Some number of people (this number is even) have stood in a circle. The people stand in the
circle evenly. They are numbered clockwise starting from a person with the number 1. Each
person is looking through the circle's center at the opposite person.
A sample of a circle of 6 persons. The orange arrows indicate who is looking at whom.
You don't know the exact number of people standing in the circle (but this number is even,
no doubt). It is known that the person with the number a is looking at the person with the
number b (and vice versa, of course). What is the number associated with a person being
looked at by the person with the number c? If, for the specified a, b, and c, no such circle
exists, output -1.
Input
The first line contains one integer t (1 ) — the number of test cases. Then t test
4
≤ t ≤ 10
cases follow.
Each test case consists of one line containing three distinct integers a, b, c (
).
8
1 ≤ a, b, c ≤ 10
Output
For each test case output in a separate line a single integer d — the number of the person
being looked at by the person with the number c in a circle such that the person with the
-
Unsolved Problem Practice Sep 01, 2023
number a is looking at the person with the number b. If there are multiple solutions, print
any of them. Output −1 if there's no circle meeting the given conditions.
Sample 1
Input Output
7 8
6 2 4 -1
2 3 1 -1
2 4 10 -1
5 3 4 4
1 3 2 1
2 5 4 -1
4 3 2
Note
In the first test case, there's a desired circle of 8 people. The person with the number 6 will
look at the person with the number 2 and the person with the number 8 will look at the
person with the number 4.
In the second test case, there's no circle meeting the conditions. If the person with the
number 2 is looking at the person with the number 3, the circle consists of 2 people because
these persons are neighbors. But, in this case, they must have the numbers 1 and 2, but it
doesn't meet the problem's conditions.
In the third test case, the only circle with the persons with the numbers 2 and 4 looking at
each other consists of 4 people. Therefore, the person with the number 10 doesn't occur in
the circle.
-
Unsolved Problem Practice Sep 01, 2023
Bizon the Champion isn't just a bison. He also is a favorite of the "Bizons" team.
At a competition the "Bizons" got the following problem: "You are given two distinct words
(strings of English letters), s and t. You need to transform word s into word t". The task
looked simple to the guys because they know the suffix data structures well. Bizon Senior
loves suffix automaton. By applying it once to a string, he can remove from this string any
single character. Bizon Middle knows suffix array well. By applying it once to a string, he
can swap any two characters of this string. The guys do not know anything about the suffix
tree, but it can help them do much more.
Bizon the Champion wonders whether the "Bizons" can solve the problem. Perhaps, the
solution do not require both data structures. Find out whether the guys can solve the
problem and if they can, how do they do it? Can they solve it either only with use of suffix
automaton or only with use of suffix array or they need both structures? Note that any
structure may be used an unlimited number of times, the structures may be used in any
order.
Input
The first line contains a non-empty word s. The second line contains a non-empty word t.
Words s and t are different. Each word consists only of lowercase English letters. Each word
contains at most 100 letters.
Output
In the single line print the answer to the problem. Print "need tree" (without the quotes)
if word s cannot be transformed into word t even with use of both suffix array and suffix
automaton. Print "automaton" (without the quotes) if you need only the suffix automaton
to solve the problem. Print "array" (without the quotes) if you need only the suffix array
to solve the problem. Print "both" (without the quotes), if you need both data structures to
solve the problem.
-
Unsolved Problem Practice Sep 01, 2023
It's guaranteed that if you can solve the problem only with use of suffix array, then it is
impossible to solve it only with use of suffix automaton. This is also true for suffix
automaton.
Sample 1
Input Output
automaton automaton
tomat
Sample 2
Input Output
array array
arary
Sample 3
Input Output
both both
hot
Sample 4
Input Output
Note
In the third sample you can act like that: first transform "both" into "oth" by removing
the first character using the suffix automaton and then make two swaps of the string using
the suffix array and get "hot".
-
Unsolved Problem Practice Sep 01, 2023
You are given a sorted array a1 , a2 , … , an (for each index i > 1 condition ai ≥ ai−1
You are asked to divide this array into k non-empty consecutive subarrays. Every element in
the array should be included in exactly one subarray.
Let max(i) be equal to the maximum in the i-th subarray, and min(i) be equal to the
k
minimum in the i-th subarray. The cost of division is equal to ∑ (max(i) − min(i)). For
i=1
example, if a = [2, 4, 5, 5, 8, 11, 19] and we divide it into 3 subarrays in the following way:
[2, 4], [5, 5], [8, 11, 19] , then the cost of division is equal to
(4 − 2) + (5 − 5) + (19 − 8) = 13.
Calculate the minimum cost you can obtain by dividing the array a into k non-empty
consecutive subarrays.
Input
Output
Print the minimum cost you can obtain by dividing the array a into k nonempty consecutive
subarrays.
Sample 1
Input Output
6 3 12
4 8 15 16 23 42
-
Unsolved Problem Practice Sep 01, 2023
Sample 2
Input Output
4 4 0
1 3 3 7
Sample 3
Input Output
8 1 20
1 1 2 3 5 8 13 21
Note
In the first test we can divide array a in the following way: [4, 8, 15, 16], [23], [42].
-
Unsolved Problem Practice Sep 01, 2023
What is the minimum number of steps you need to make the sum of array ∑ ai ≤ k? (You
i=1
Input
The first line contains a single integer t (1 ) — the number of test cases.
4
≤ t ≤ 10
The first line of each test case contains two integers n and k (1 ;
5
≤ n ≤ 2 ⋅ 10
array itself.
It's guaranteed that the sum of n over all test cases doesn't exceed 2 ⋅ 10 .
5
Output
n
For each test case, print one integer — the minimum number of steps to make ∑ ai ≤ k.
i=1
Sample 1
-
Unsolved Problem Practice Sep 01, 2023
Input Output
4 10
1 10 0
20 2
2 69 7
6 9
7 8
1 2 1 3 1 2 1
10 1
1 2 3 1 2 6 1 6 8 10
Note
In the first test case, you should decrease a1 10 times to get the sum lower or equal to
k = 10 .
In the second test case, the sum of array a is already less or equal to 69, so you don't need to
change it.
1. set a4 = a3 = 1 ;
As a result, you'll get array [1, 2, 1, 0, 1, 2, 1] with sum less or equal to 8 in 1 + 1 = 2 steps.
As a result, you'll get array [1, 2, 3, 1, 2, −2, −2, −2, −2, −2] with sum less or equal to 1 in
3 + 4 = 7 steps.
-
Unsolved Problem Practice Sep 01, 2023
For the multiset of positive integers s = {s1 , s2 , … , sk } , define the Greatest Common
Divisor (GCD) and Least Common Multiple (LCM) of s as follow:
gcd(s) is the maximum positive integer x , such that all integers in s are divisible on
x.
lcm(s) is the minimum positive integer x , that divisible on all integers from s.
For example, gcd({8, 12}) = 4, gcd({12, 18, 6}) = 6 and lcm({4, 6}) = 12 . Note that
for any positive integer x , gcd({x}) = lcm({x}) = x .
Input
Output
Sample 1
Input Output
2 1
1 1
Sample 2
-
Unsolved Problem Practice Sep 01, 2023
Input Output
4 40
10 24 40 80
Sample 3
Input Output
10 54
540 648 810 648 720 540 594 864 972 648
Note
For the second example, t = {120, 40, 80, 120, 240, 80} , and it's not hard to see that
gcd(t) = 40 .
-
Unsolved Problem Practice Sep 01, 2023
CQXYM wants to create a connected undirected graph with n nodes and m edges, and the
diameter of the graph must be strictly less than k − 1 . Also, CQXYM doesn't want a graph
that contains self-loops or multiple edges (i.e. each edge connects two different vertices
and between each pair of vertices there is at most one edge).
The diameter of a graph is the maximum distance between any two nodes.
The distance between two nodes is the minimum number of the edges on the path which
endpoints are the two nodes.
Input
The first line contains an integer t(1 — the number of test cases. The
5
≤ t ≤ 10 )
Only one line of each test case contains three integers n(1 ≤ n ≤ 10 ), m, k
9
(0 ≤ m, k ≤ 10 ) .
9
Output
For each test case, print YES if it is possible to create the graph, or print NO if it is
impossible. You can print each letter in any case (upper or lower).
Sample 1
-
Unsolved Problem Practice Sep 01, 2023
Input Output
5 YES
1 0 3 NO
4 5 3 YES
4 6 3 NO
5 4 1 NO
2 1 1
Note
-
Unsolved Problem Practice Sep 01, 2023
Two men are moving concurrently, one man is moving from A to B and other man is moving
from C to D. Initially the first man is at A, and the second man is at C. They maintain
constant velocities such that when the first man reaches B, at the same time the second
man reaches D. You can assume that A, B, C and D are 2D Cartesian co-ordinates. You have
to find the minimum Euclidean distance between them along their path.
Input
Each case will contain eight integers: Ax, Ay, Bx, By, Cx, Cy, Dx, Dy. All the co-ordinates are
between 0 and 100. (Ax, Ay) denotes A. (Bx, By) denotes B and soon.
Output
For each case, print the case number and the minimum distance between them along their
Sample
Input Output
3 Case 1: 0
0 0 5 0 5 5 5 0 Case 2: 1.4142135624
0 0 5 5 10 10 6 6 Case 3: 1
0 0 5 0 10 1 1 1
-
Unsolved Problem Practice Sep 01, 2023
Problem Statement
Mr. Takaha decides to make a multi-dimensional burger in his party. A level-L burger (L is
an integer greater than or equal to 0) is the following thing:
For example, a level-1 burger and a level-2 burger look like BPPPB and BBPPPBPBPPPBB
(rotated 90 degrees), where B and P stands for a bun and a patty.
The burger Mr. Takaha will make is a level-N burger. Lunlun the Dachshund will eat X
layers from the bottom of this burger (a layer is a patty or a bun). How many patties will she
eat?
Constraints
1 ≤ N ≤ 50
1 ≤ X ≤ ( the total number of layers in a level-N burger )
N and X are integers.
Input
N X
Output
-
Unsolved Problem Practice Sep 01, 2023
Print the number of patties in the bottom-most X layers from the bottom of a level-N
burger.
Sample 1
Input Output
2 7 4
Sample 2
Input Output
1 1 0
Sample 3
Input Output
50 4321098765432109 2160549382716056
A level-50 burger is rather thick, to the extent that the number of its layers does not fit into
a 32-bit integer.
-
Problem O — limit 2 seconds
Grid
You are on the top left square of an m × n grid, where each square on the grid has a digit on it.
From a given square that has digit k on it, a move consists of jumping exactly k squares in one of
the four cardinal directions. What is the minimum number of moves required to get from the top
left corner to the bottom right corner?
Input
The rst line of input contains two space-separated positive integers m and n (1 ≤ m, n ≤ 500). It
is guaranteed that at least one of m and n is greater than 1. The next m lines each consists of n
digits, describing the m × n grid. Each digit is between 0 and 9.
Output
Print, on a single line, a single integer denoting the minimum number of moves needed to get from
the top-left corner to the bottom-right corner. If it is impossible to reach the bottom-right corner,
print IMPOSSIBLE instead.