Solutions are presented as using the least memory and the fastest execution time. It also takes the top
10 most recent solutions from each language. If you want to limit to a specific index, click the
"Solved" button and go to that problem.
Problems
This is an interactive problem. You are given an unknown binary string (s)(^{\text{∗}}) of length (n). The function (f(l, r)) is defined as the number of distinct elements in the array (a) formed by the following operation: Let (S) be the substring (s_l s_{l+1} \ldots s_r). Let (m) be the length of the substring. We start with an empty array (a). For the (i)-th ((0 \le i \lt m)) left cyclic rotation(^{\text{†}}) of (S), let's denote the number of inversions(^{\text{‡}}) as (x_{i}). For every (i) such that (0 \le i \lt m), append (x_{i} \mbox{ mod } m) to the array (a), where (u \mbox{ mod } v) denotes the remainder of dividing (u) by (v). To determine (s), you can ask some questions. In each question, you can choose (2) integers (l) and (r) ((1 \le l \le r \le n)) and get the value of (f(l, r)). Asking each query incurs a cost of (\dfrac{n}{r-l+1}). Note that the cost does not necessarily have to be an integer. You have to determine the hidden binary string while keeping the total cost of queries atmost (\mathbf{max(30,3\cdot n)}). You are allowed to make at most (\mathbf{2}) guesses. (^{\text{∗}})A binary string only contains characters (0) and (1). (^{\text{†}})Let there be a binary string (s \; = \; s_{1}s_{2}\cdots s_{n}). The (k)-th left cyclic rotation of (s) is defined as (t_{k} \; = \; s_{k+1}s_{k+2}\cdots s_{n}s_{1}s_{2}\cdots s_{k}). (^{\text{‡}})Let there be a string (s \; = \; s_{1}s_{2}\cdots s_{n}). The number of inversions of (s) is defined as the number of pairs of indices (i,j \; (1 \le i \lt j \le n)), such that (s_{i} \gt s_{j}). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 100)). The description of the test cases follows. The first line of each test case contains a single integ |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|
368765641 |
caffeine2ac |
E |
March 29, 2026, 4:44 p.m. |
OK |
C# 13 |
TESTS |
23 |
93 |
14336000 |
|
|
remove filters
Back to search problems