text
stringlengths 0
801
|
---|
You are given a grid with $n$ rows and $m$ columns. You need to fill each cell with a unique integer from $1$ to $n \cdot m$.
|
After filling the grid, you will play a game on this grid against the interactor. Players take turns selecting one of the previously unselected cells from the grid, with the interactor going first.
|
On the first turn, the interactor can choose any cell from the grid. After that, any chosen cell must be orthogonally adjacent to at least one previously selected cell. Two cells are considered orthogonally adjacent if they share an edge. The game continues until all cells have been selected.
|
Your goal is to let the sum of numbers in the cells selected by you be strictly less than the sum of numbers in the cells selected by the interactor.
|
Each test contains multiple test cases. The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases. The description of test cases follows.
|
The only line of each test case contains two integers $n$ and $m$ ($4 \le n, m \le 10$) — the number of rows and columns in the grid.
|
Note that this is an example game and does not necessarily represent the optimal strategy for both players.
|
First, we fill a $4 \times 4$ grid with unique integers from $1$ to $16$ in the following way:
|
$2$| $3$| $4$| $10$ ---|---|---|--- $12$| $6$| $11$| $15$ $5$| $13$| $16$| $8$ $9$| $7$| $1$| $14$ Next, the game begins.
|
1. The interactor first selects $(3, 4)$, which is the number $8$. For this selection, the interactor could choose any number. From the next selection onwards, each chosen number has to be adjacent to any previously selected number. 2. We select $(2, 4)$, which is the number $15$, adjacent to $(3, 4)$. 3. The interactor selects $(4, 4)$, which is the number $14$, adjacent to $(3, 4)$. 4. We select $(4, 3)$, which is the number $1$, adjacent to $(4, 4)$. 5. $\ldots$ 6. This is continued until all numbers are selected.
|
In the end, the numbers we selected were $[15,
|
Kmes has written three integers $a$, $b$ and $c$ in order to remember that he has to give Noobish_Monk $a \times b \times c$ bananas.
|
Noobish_Monk has found these integers and decided to do the following at most $5$ times:
|
* pick one of these integers; * increase it by $1$.
|
For example, if $a = 2$, $b = 3$ and $c = 4$, then one can increase $a$ three times by one and increase $b$ two times. After that $a = 5$, $b = 5$, $c = 4$. Then the total number of bananas will be $5 \times 5 \times 4 = 100$.
|
What is the maximum value of $a \times b \times c$ Noobish_Monk can achieve with these operations?
|
Each test contains multiple test cases. The first line of input contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The description of the test cases follows.
|
The first and only line of each test case contains three integers $a$, $b$ and $c$ ($1 \le a, b, c \le 10$) — Kmes's integers.
|
For each test case, output a single integer — the maximum amount of bananas Noobish_Monk can get.
|
Gorilla and Noobish_Monk found three numbers $n$, $m$, and $k$ ($m < k$). They decided to construct a permutation$^{\dagger}$ of length $n$.
|
For the permutation, Noobish_Monk came up with the following function: $g(i)$ is the sum of all the numbers in the permutation on a prefix of length $i$ that are not greater than $m$. Similarly, Gorilla came up with the function $f$, where $f(i)$ is the sum of all the numbers in the permutation on a prefix of length $i$ that are not less than $k$. A prefix of length $i$ is a subarray consisting of the first $i$ elements of the original array.
|
For example, if $n = 5$, $m = 2$, $k = 5$, and the permutation is $[5, 3, 4, 1, 2]$, then:
|
* $f(1) = 5$, because $5 \ge 5$; $g(1) = 0$, because $5 > 2$; * $f(2) = 5$, because $3 < 5$; $g(2) = 0$, because $3 > 2$; * $f(3) = 5$, because $4 < 5$; $g(3) = 0$, because $4 > 2$; * $f(4) = 5$, because $1 < 5$; $g(4) = 1$, because $1 \le 2$; * $f(5) = 5$, because $2 < 5$; $g(5) = 1 + 2 = 3$, because $2 \le 2$.
|
Help them find a permutation for which the value of $\left(\sum_{i=1}^n f(i) - \sum_{i=1}^n g(i)\right)$ is maximized.
|
$^{\dagger}$A permutation of length $n$ is an array consisting of $n$ distinct integers from $1$ to $n$ in any order. For example, $[2,3,1,5,4]$ is a permutation, but $[1,2,2]$ is not a permutation (as $2$ appears twice in the array) and $[1,3,4]$ is also not a permutation (as $n=3$, but $4$ appears in the array).
|
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
|
The only line of each case contains three integers $n$, $m$, $k$ ($2\le n \le 10^5$; $1 \le m < k \le n$) — the size of the permutation to be constructed and two integers.
|
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$.
|
For each test case, output the permutation — a set of numbers that satisfies the conditions of the problem. If there are multiple solutions, output any of them.
|
In the first example, $\left(\sum_{i=1}^n f(i) - \sum_{i=1}^n g(i)\righ
|
In his favorite cafe Kmes once again wanted to try the herring under a fur coat. Previously, it would not have been difficult for him to do this, but the cafe recently introduced a new purchasing policy.
|
Now, in order to make a purchase, Kmes needs to solve the following problem: $n$ cards with prices for different positions are laid out in front of him, on the $i$-th card there is an integer $a_i$, among these prices there is no whole positive integer $x$.
|
Kmes is asked to divide these cards into the minimum number of bad segments (so that each card belongs to exactly one segment). A segment is considered bad if it is impossible to select a subset of cards with a product equal to $x$. All segments, in which Kmes will divide the cards, must be bad.
|
Formally, the segment $(l, r)$ is bad if there are no indices $i_1 < i_2 < \ldots < i_k$ such that $l \le i_1, i_k \le r$, and $a_{i_1} \cdot a_{i_2} \ldots \cdot a_{i_k} = x$.
|
Help Kmes determine the minimum number of bad segments in order to enjoy his favorite dish.
|
The first line contains a single integer $t$ ($1 \le t \le 10^3$) — the number of test cases.
|
The first line of each set of input data gives you $2$ integers $n$ and $x$ ($1 \le n \le 10^5, 2 \le x \le 10^5$) — the number of cards and the integer, respectively.
|
The second line of each set of input data contains $n$ integers $a_i$ ($1 \le a_i \le 2 \cdot 10^5, a_i \neq x$) — the prices on the cards.
|
It is guaranteed that the sum of $n$ over all sets of test data does not exceed $10^5$.
|
For each set of input data, output the minimum number of bad segments.
|
K1o0n gave you an array $a$ of length $n$, consisting of numbers $1, 2, \ldots, n$. Accept it? Of course! But what to do with it? Of course, calculate $\text{MEOW}(a)$.
|
Let $\text{MEX}(S, k)$ be the $k$-th positive (strictly greater than zero) integer in ascending order that is not present in the set $S$. Denote $\text{MEOW}(a)$ as the sum of $\text{MEX}(b, |b| + 1)$, over all distinct subsets $b$ of the array $a$.
|
Examples of $\text{MEX}(S, k)$ values for sets:
|
* $\text{MEX}(\\{3,2\\}, 1) = 1$, because $1$ is the first positive integer not present in the set; * $\text{MEX}(\\{4,2,1\\}, 2) = 5$, because the first two positive integers not present in the set are $3$ and $5$; * $\text{MEX}(\\{\\}, 4) = 4$, because there are no numbers in the empty set, so the first $4$ positive integers not present in it are $1, 2, 3, 4$.
|
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
|
In a single line of each test case, an integer $n$ ($1 \le n \le 5000$) is entered, the size of the array of gifted numbers.
|
It is guaranteed that the sum of $n^2$ over all test cases does not exceed $25 \cdot 10^6$.
|
For each test case, output a single number — $\text{MEOW}(a)$. Since it may be very large, output it modulo $10^9 + 7$.
|
Tim is doing a test consisting of $4n$ questions; each question has $4$ options: 'A', 'B', 'C', and 'D'. For each option, there are exactly $n$ correct answers corresponding to that option — meaning there are $n$ questions with the answer 'A', $n$ questions with the answer 'B', $n$ questions with the answer 'C', and $n$ questions with the answer 'D'.
|
For each question, Tim wrote his answer on the answer sheet. If he could not figure out the answer, he would leave a question mark '?' for that question.
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.