text
stringlengths 0
801
|
---|
You are given his answer sheet of $4n$ characters. What is the maximum number of correct answers Tim can get? |
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. |
The first line of each test case contains an integer $n$ ($1 \le n \le 100$). |
The second line of each test case contains a string $s$ of $4n$ characters ($s_i \in \\{\texttt{A}, \texttt{B}, \texttt{C}, \texttt{D}, \texttt{?}\\}$) — Tim's answers for the questions. |
For each test case, print a single integer — the maximum score that Tim can achieve. |
In the first test case, there is exactly one question with each answer 'A', 'B', 'C', and 'D'; so it's possible that Tim gets all his answers correct. |
In the second test case, there are only two correct answers 'A' which makes him get exactly $2$ points in any case. |
In the third test case, Tim can get at most $2$ correct answers with option 'A' and $2$ correct answers with option 'B'. For example, he would get $4$ points if the answers were 'AACCBBDD'. |
In the fourth test case, he refuses to answer any question at all, which makes him get $0$ points. |
There is an apartment consisting of $n$ rooms, each with its light initially turned off. |
To control the lights in these rooms, the owner of the apartment decided to install chips in the rooms so that each room has exactly one chip, and the chips are installed at different times. Specifically, these times are represented by the array $a_1, a_2, \ldots, a_n$, where $a_i$ is the time (in minutes) at which a chip is installed in the $i$-th room. |
As soon as a chip is installed, it changes the room's light status every $k$ minutes — it turns on the light for $k$ minutes, then turns it off for the next $k$ minutes, then turns it back on for the next $k$ minutes, and so on. In other words, the light status is changed by the chip at minute $a_i$, $a_i + k$, $a_i + 2k$, $a_i + 3k$, $\ldots$ for the $i$-th room. |
What is the earliest moment when all rooms in the apartment have their lights turned on? |
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. |
The first line of each test case contains two integers $n$ and $k$ ($1 \le k \le n \le 2 \cdot 10^5$) — the number of rooms in the apartment and the period of the chips. |
The second line contains $n$ distinct integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$) — the moments when the chips are installed. |
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$. |
For each test case, print a single integer — the answer to the question (in minutes). If there is no such moment that the lights are turned on in all the rooms, print $-1$ instead. |
In the first test case, all lights will be on by the minute $5$ without any of them being turned off by the chips. The answer is $5$. |
In the second test case, due to $k=3$, the $1$-st light will be on at minutes $2, 3, 4, 8, 9, 10, 14, \ldots$; meanwhile, the $4$-th light will be on at minutes $5, 6, 7, 11, 12, 13, 17, \ldots$. These two sequences don't have any number in common, so they will never be on at the same time. |
In the third test case, it |
Given a matrix $a$ of size $n \times m$, each cell of which contains a non-negative integer. The integer lying at the intersection of the $i$-th row and the $j$-th column of the matrix is called $a_{i,j}$. |
Let's define $f(i)$ and $g(j)$ as the [XOR](https://en.wikipedia.org/wiki/Exclusive_or) of all integers in the $i$-th row and the $j$-th column, respectively. In one operation, you can either: |
* Select any row $i$, then assign $a_{i,j} := g(j)$ for each $1 \le j \le m$; or * Select any column $j$, then assign $a_{i,j} := f(i)$ for each $1 \le i \le n$. |
 An example of applying an operation on column $2$ of the matrix. |
In this example, as we apply an operation on column $2$, all elements in this column are changed: |
* $a_{1,2} := f(1) = a_{1,1} \oplus a_{1,2} \oplus a_{1,3} \oplus a_{1,4} = 1 \oplus 1 \oplus 1 \oplus 1 = 0$ * $a_{2,2} := f(2) = a_{2,1} \oplus a_{2,2} \oplus a_{2,3} \oplus a_{2,4} = 2 \oplus 3 \oplus 5 \oplus 7 = 3$ * $a_{3,2} := f(3) = a_{3,1} \oplus a_{3,2} \oplus a_{3,3} \oplus a_{3,4} = 2 \oplus 0 \oplus 3 \oplus 0 = 1$ * $a_{4,2} := f(4) = a_{4,1} \oplus a_{4,2} \oplus a_{4,3} \oplus a_{4,4} = 10 \oplus 11 \oplus 12 \oplus 16 = 29$ |
You can apply the operations any number of times. Then, we calculate the $\textit{beauty}$ of the final matrix by summing the absolute differences between all pairs of its adjacent cells. |
More formally, $\textit{beauty}(a) = \sum|a_{x,y} - a_{r,c}|$ for all cells $(x, y)$ and $(r, c)$ if they are adjacent. Two cells are considered adjacent if they share a side. |
Find the minimum $\textit{beauty}$ among all obtainable matrices. |
The first line contains a single integer $t$ ($1 \le t \le 250$) — the number of test cases. |
The first line of each test case contains two integers $n$ and $m$ ($1 \le n, m \le 15$) — the number of rows and columns of $a$, respectively. |
The next $n$ lines, each containing $m$ integers $a_{i,1}, a_{i,2}, \ldots, a_{i,m}$ ($0 \le a_{i,j} < 2^{20}$) — description |
This is the easy version of the problem. The only difference is that in this version $k \le n$. You can make hacks only if both versions of the problem are solved. Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle. |
You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively. |
The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows: |
* If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's). * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's). |
Then, it will execute the changed script starting from the character which it couldn't execute. |
 An example of the robot's movement process, $s = \texttt{"ULULURD"}$ |
The script $s$ will be executed for $k$ times continuously. All changes to the string $s$ will be retained even when it is repeated. During this process, how many times will the robot move to the point $(0, 0)$ in total? Note that the initial position does NOT count. |
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. |
The first line of each test case contains four integers $n$, $k$, $w$, and $h$ ($1 \le n, w, h \le 10^6$; $1 \le k \le n$). |
The second line contains a single string $s$ of size $n$ ($s_i \in \\{\texttt{L}, \texttt{R}, \texttt{U}, \texttt{D}\\}$) — the script to be executed. |
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$. |
For each test case, print a single integer — the number of times the robot reaches $(0, 0)$ when executing script $s$ for $k$ times continuously. |
In the first test case, the robot only moves up and right. In the end, it occupies the position $(2, 2)$ |
This is the hard version of the problem. The only difference is that in this version $k \le 10^{12}$. You can make hacks only if both versions of the problem are solved. |
Given a $w \times h$ rectangle on the $Oxy$ plane, with points $(0, 0)$ at the bottom-left and $(w, h)$ at the top-right of the rectangle. |
You also have a robot initially at point $(0, 0)$ and a script $s$ of $n$ characters. Each character is either L, R, U, or D, which tells the robot to move left, right, up, or down respectively. |
The robot can only move inside the rectangle; otherwise, it will change the script $s$ as follows: |
* If it tries to move outside a vertical border, it changes all L characters to R's (and vice versa, all R's to L's). * If it tries to move outside a horizontal border, it changes all U characters to D's (and vice versa, all D's to U's). |
Then, it will execute the changed script starting from the character which it couldn't execute. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.