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.
ContestId |
Name |
Phase |
Frozen |
Duration (Seconds) |
Relative Time |
Start Time |
|---|---|---|---|---|---|---|
| 2085 | Codeforces Round 1011 (Div. 2) | FINISHED | False | 7200 | 33751523 | March 22, 2025, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 3119 ) | E | Serval and Modulo | PROGRAMMING | brute force constructive algorithms math number theory |
There is an array (a) consisting of (n) non-negative integers and a magic number (k) ((k\ge 1), (k) is an integer). Serval has constructed another array (b) of length (n), where (b_i = a_i \bmod k) holds(^{\text{∗}}) for all (1\leq i\leq n). Then, he shuffled (b). You are given the two arrays (a) and (b). Find a possible magic number (k). However, there is a small possibility that Serval fooled you, and such an integer does not exist. In this case, output (-1). It can be shown that, under the constraints of the problem, if such an integer (k) exists, then there exists a valid answer no more than (10^9). And you need to guarantee that (k\le 10^9) in your output. (^{\text{∗}})(a_i \bmod k) denotes the remainder from dividing (a_i) by (k). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^4)). The description of the test cases follows. The first line of each test case contains an integer (n) ((1\leq n\leq 10^4)) — the length of the array (a). The second line contains (n) integers (a_1, a_2, \ldots, a_n) ((0\leq a_i\leq 10^6)) — the elements of the array (a). The third line contains (n) integers (b_1, b_2, \ldots, b_n) ((0\leq b_i\leq 10^6)) — the elements of the array (b). It is guaranteed that the sum of (n) over all test cases does not exceed (10^4). For each test case, output a single integer (k) ((1\leq k\leq 10^9)) — the magic number you found. Print (-1) if it is impossible to find such an integer. If there are multiple answers, you may print any of them. In the first test case, if (k\ge 3), then (2=a_3\bmod k) should be in the array (b), which leads to a contradiction. For (k = 1), (a_1\bmod k, a_2\bmod k, a_3\bmod k, a_4 \bmod k = 0,0,0,0), which cannot be shuffled to (b). For (k = 2), $$$[a_1\bmod k, a_ |
| Codeforces Round #1011 (Div. 2) Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 311945429 | masonpop | E | March 23, 2025, 2:08 a.m. | OK | C++17 (GCC 7-32) | TESTS | 63 | 77 | 4198400 | ||
| 311915834 | farmerboy | E | March 22, 2025, 7:24 p.m. | OK | C++17 (GCC 7-32) | TESTS | 62 | 78 | 4198400 | ||
| 311956469 | cp_first | E | March 23, 2025, 4:57 a.m. | OK | C++17 (GCC 7-32) | TESTS | 63 | 93 | 102400 | ||
| 311898541 | cryptic_cook | E | March 22, 2025, 5:13 p.m. | OK | C++17 (GCC 7-32) | TESTS | 60 | 125 | 102400 | ||
| 311894282 | anuj31032001 | E | March 22, 2025, 4:34 p.m. | OK | C++17 (GCC 7-32) | TESTS | 60 | 140 | 0 | ||
| 311953758 | battak | E | March 23, 2025, 4:23 a.m. | OK | C++17 (GCC 7-32) | TESTS | 63 | 140 | 102400 | ||
| 311896372 | CAELO | E | March 22, 2025, 5:03 p.m. | OK | C++17 (GCC 7-32) | TESTS | 60 | 140 | 102400 | ||
| 311909931 | vss_1307 | E | March 22, 2025, 6:32 p.m. | OK | C++17 (GCC 7-32) | TESTS | 61 | 140 | 1740800 | ||
| 311907408 | durduryu | E | March 22, 2025, 6:12 p.m. | OK | C++17 (GCC 7-32) | TESTS | 60 | 140 | 32153600 | ||
| 311924392 | _SohamK | E | March 22, 2025, 8:48 p.m. | OK | C++17 (GCC 7-32) | TESTS | 62 | 155 | 102400 | ||
| 311907228 | luckyblock233 | E | March 22, 2025, 6:10 p.m. | OK | C++20 (GCC 13-64) | TESTS | 60 | 77 | 8192000 | ||
| 311927186 | Alexbrii | E | March 22, 2025, 9:11 p.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 78 | 12083200 | ||
| 311918400 | DaNeK0201 | E | March 22, 2025, 7:49 p.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 92 | 4096000 | ||
| 311896487 | Mint_Victoria | E | March 22, 2025, 5:03 p.m. | OK | C++20 (GCC 13-64) | TESTS | 60 | 92 | 4096000 | ||
| 311905786 | pskobx | E | March 22, 2025, 5:59 p.m. | OK | C++20 (GCC 13-64) | TESTS | 60 | 93 | 102400 | ||
| 311923450 | DaNeK0201 | E | March 22, 2025, 8:42 p.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 93 | 4096000 | ||
| 311920436 | imgm228 | E | March 22, 2025, 8:11 p.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 93 | 4096000 | ||
| 311918205 | DaNeK0201 | E | March 22, 2025, 7:47 p.m. | OK | C++20 (GCC 13-64) | TESTS | 62 | 93 | 4096000 | ||
| 311899795 | Zyc77 | E | March 22, 2025, 5:20 p.m. | OK | C++20 (GCC 13-64) | TESTS | 60 | 93 | 4096000 | ||
| 311897393 | Mint_Victoria | E | March 22, 2025, 5:07 p.m. | OK | C++20 (GCC 13-64) | TESTS | 60 | 93 | 4096000 |
Back to search problems