title-img


Sum of the Maximums

Alexey is playing with an array, , of integers. His friend, Ivan, asks him to calculate the sum of the maximum values for all subsegments of . More formally, he wants Alexey to find . Alexey solved Ivan's challenge faster than expected, so Ivan decides to add another layer of difficulty by having Alexey answer queries. The query contains subsegment , and he must calculate the sum of maximum values on all subsegments inside subsegment . More formally, for each query , Alexey must calcula

View Solution →

Connected Cells in a Grid

Consider a matrix where each cell contains either a 0 or a 1. Any cell containing a 1 is called a filled cell. Two cells are said to be connected if they are adjacent to each other horizontally, vertically, or diagonally. In the following grid, all cells marked X are connected to the cell marked Y. XXX XYX XXX If one or more filled cells are also connected, they form a region. Note that each cell in a region is connected to zero or more cells in the region but is not necessarily dire

View Solution →

Manipulative Numbers

Suppose that is a list of numbers and is a permutation of these numbers, we say B is K-Manipulative if and only if: is not less than , where represents the XOR operator. You are given . Find the largest such that there exists a K-manipulative permutation . Input: The first line is an integer . The second line contains space separated integers - . Output: The largest possible , or if there is no solution.

View Solution →

K Factorization

At the time when Pythagoreanism was prevalent, people were also focused on different ways to factorize a number. In one class, Pythagoras asked his disciples to solve one such problem, Reverse Factorization. They were given a set of integer, , and an integer . They need to find the a way to reach , starting from , and at each step multiplying current value by any element of . But soon they realised that there may exist more than one way to reach . So they decided to find a way in which number of

View Solution →

Simplified Chess Engine II

Chess is a very popular game played by hundreds of millions of people. Nowadays, we have chess engines such as Stockfish and Komodo to help us analyze games. These engines are very powerful pieces of well-developed software that use intelligent ideas and algorithms to analyze positions and sequences of moves, as well as to find tactical ideas. Consider the following simplified version of chess: Board: It's played on a board between two players named Black and White. Rows are numbered from

View Solution →