[Solution] Palindromic Numbers solution codeforces

Palindromic Numbers solution codeforces – During a daily walk Alina noticed a long number written on the ground. Now Alina wants to find some positive number of same length without leading zeroes, such that the sum of these two numbers is a palindrome. [Solution] Palindromic Numbers solution codeforces Recall that a number is called a … Read more

[Solution] Optimal Path solution codeforces

Optimal Path solution codeforces – You are given a table 𝑎a of size 𝑛×𝑚n×m. We will consider the table rows numbered from top to bottom from 11 to 𝑛n, and the columns numbered from left to right from 11 to 𝑚m. We will denote a cell that is in the 𝑖i-th row and in the 𝑗j-th column as (𝑖,𝑗)(i,j). In the cell (𝑖,𝑗)(i,j) there is written a number (𝑖−1)⋅𝑚+𝑗(i−1)⋅m+j, … Read more

[Solution] Ambiguous Dominoes solution codeforces

Ambiguous Dominoes solution codeforces – Polycarp and Monocarp are both solving the same puzzle with dominoes. They are given the same set of 𝑛n dominoes, the 𝑖i-th of which contains two numbers 𝑥𝑖xi and 𝑦𝑖yi. They are also both given the same 𝑚m by 𝑘k grid of values 𝑎𝑖𝑗aij such that 𝑚⋅𝑘=2𝑛m⋅k=2n. [Solution] Ambiguous Dominoes solution codeforces The puzzle asks them to place the 𝑛n dominoes on the grid … Read more

[Solution] Tree Queries (Hard Version) solution codeforces

Tree Queries (Hard Version) solution codeforces – You are given an unrooted tree with 𝑛n vertices. There is some hidden vertex 𝑥x in that tree that you are trying to find. [Solution] Tree Queries (Hard Version) solution codeforces To do this, you may ask 𝑘k queries 𝑣1,𝑣2,…,𝑣𝑘v1,v2,…,vk where the 𝑣𝑖vi are vertices in the tree. After you are finished asking all of the queries, … Read more

[Solution] Tree Queries (Easy Version) solution codeforces

Tree Queries (Easy Version) solution codeforces – You are given an unrooted tree with 𝑛n vertices. There is some hidden vertex 𝑥x in that tree that you are trying to find. [Solution] Tree Queries (Easy Version) solution codeforces To do this, you may ask 𝑘k queries 𝑣1,𝑣2,…,𝑣𝑘v1,v2,…,vk where the 𝑣𝑖vi are vertices in the tree. After you are finished asking all of the queries, … Read more

[Solution] Zero Path solution codeforces

Zero Path solution codeforces – You are given a grid with 𝑛n rows and 𝑚m columns. We denote the square on the 𝑖i-th (1≤𝑖≤𝑛1≤i≤n) row and 𝑗j-th (1≤𝑗≤𝑚1≤j≤m) column by (𝑖,𝑗)(i,j) and the number there by 𝑎𝑖𝑗aij. All numbers are equal to 11 or to −1−1. [Solution] Zero Path solution codeforces You start from the square (1,1)(1,1) and can move one square down or one square to the … Read more

[Solution] Circle Game solution codeforces

Circle Game solution codeforces – Mike and Joe are playing a game with some stones. Specifically, they have 𝑛n piles of stones of sizes 𝑎1,𝑎2,…,𝑎𝑛a1,a2,…,an. These piles are arranged in a circle. [Solution] Circle Game solution codeforces The game goes as follows. Players take turns removing some positive number of stones from a pile in clockwise order … Read more

[Solution] Subrectangle Guess solution codeforces

Subrectangle Guess solution codeforces – Michael and Joe are playing a game. The game is played on a grid with 𝑛n rows and 𝑚m columns, filled with distinct integers. We denote the square on the 𝑖i-th (1≤𝑖≤𝑛1≤i≤n) row and 𝑗j-th (1≤𝑗≤𝑚1≤j≤m) column by (𝑖,𝑗)(i,j) and the number there by 𝑎𝑖𝑗aij. [Solution] Subrectangle Guess solution codeforces Michael starts by saying two numbers ℎh (1≤ℎ≤𝑛1≤h≤n) and 𝑤w (1≤𝑤≤𝑚1≤w≤m). Then Joe … Read more

[Solution] Decinc Dividing solution codeforces

Decinc Dividing solution codeforces – Let’s call an array 𝑎a of 𝑚m integers 𝑎1,𝑎2,…,𝑎𝑚a1,a2,…,am Decinc if 𝑎a can be made increasing by removing a decreasing subsequence (possibly empty) from it. [Solution] Decinc Dividing solution codeforces For example, if 𝑎=[3,2,4,1,5]a=[3,2,4,1,5], we can remove the decreasing subsequence [𝑎1,𝑎4][a1,a4] from 𝑎a and obtain 𝑎=[2,4,5]a=[2,4,5], which is increasing. You are given a permutation 𝑝p of numbers from 11 to 𝑛n. Find the number of pairs of integers (𝑙,𝑟)(l,r) with 1≤𝑙≤𝑟≤𝑛1≤l≤r≤n such that 𝑝[𝑙…𝑟]p[l…r] (the … Read more