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 |
|---|---|---|---|---|---|---|
| 2227 | Codeforces Round 1096 (Div. 3) | FINISHED | False | 9000 | 2820287 | April 30, 2026, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 19561 ) | C | Snowfall | PROGRAMMING | constructive algorithms math |
Yousef has given you an array (a) of (n) positive integers. Let (f(a)) denote the number of subarrays(^{\text{∗}}) of (a) whose product is divisible by (6). More formally, for every pair of indices (l) and (r) such that (1 \le l \le r \le n), consider the subarray (a_l, a_{l+1}, \dots, a_r). This subarray is counted if the product of its elements is divisible by (6). For example, if (a = 1, 6, 2), then the subarrays whose products are divisible by (6) are (6), (1, 6), (6, 2), and (1, 6, 2), so (f(a) = 4). Your task is to reorder the elements of the array (a) so that (f(a)) is minimized. If there are multiple ways to do this, you may output any of them. (^{\text{∗}})An array (b) is a subarray of an array (a) if (b) can be obtained from (a) by deleting several (possibly zero or all) elements from the beginning and several (possibly zero or all) elements from the end. The first line of the input contains an integer (t) ((1 \le t \le 10^4)) — the number of test cases. The first line of each test case contains an integer (n) ((1 \le n \le 2 \cdot 10^5)) — the size of the array. The second line of each test case contains (n) integers (a_1, a_2, \dots, a_n) ((1 \le a_i \le 10^9)) — the elements of the array. 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 array after reordering it in such a way that (f(a)) is minimized. If there are multiple answers, you may output any of them. In the first test case, an optimal arrangement is (a = 12, 18, 4, 7, 5, 9). The subarrays whose products are divisible by (6) are: (12) (18) (12, 18) (18, 4) (12, 18, 4) (18, 4, 7) (12, 18, 4, 7) (18, 4, 7, 5) (4, 7, 5, 9) (12, 18, 4, 7, 5) (18, 4, 7, 5, 9) (12, 18, 4, 7, 5, 9) Therefore, $$ |
| Codeforces Round 1096 (Div. 3) — Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 373152400 | dsasdsaa | C | April 30, 2026, 4:37 p.m. | OK | C# 10 | TESTS | 4 | 125 | 22937600 | ||
| 373170506 | Amilcarqs | C | April 30, 2026, 6:47 p.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 31 | 0 | ||
| 373163230 | Quicksvolex | C | April 30, 2026, 5:22 p.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 46 | 0 | ||
| 373151279 | kareem_kio | C | April 30, 2026, 4:33 p.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 46 | 0 | ||
| 373149616 | Moinul-hasan-786 | C | April 30, 2026, 4:29 p.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 46 | 0 | ||
| 373149171 | _MIGHT_ | C | April 30, 2026, 4:27 p.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 46 | 0 | ||
| 373149087 | kunal_nalawade_03 | C | April 30, 2026, 4:27 p.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 46 | 0 | ||
| 373189150 | sarveshdhake | C | May 1, 2026, 2:42 a.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 46 | 0 | ||
| 373163676 | olga_iliasova | C | April 30, 2026, 5:26 p.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 46 | 0 | ||
| 373155124 | hawk-kun | C | April 30, 2026, 4:46 p.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 46 | 2560000 | ||
| 373200048 | anshthapliyal72 | C | May 1, 2026, 6:07 a.m. | OK | C++17 (GCC 7-32) | TESTS | 4 | 62 | 0 | ||
| 373148826 | satvik.damdhar | C | April 30, 2026, 4:26 p.m. | OK | C# 8 | TESTS | 4 | 93 | 18227200 | ||
| 373149157 | mehul.dwari | C | April 30, 2026, 4:27 p.m. | OK | C# 8 | TESTS | 4 | 93 | 18227200 |
Back to search problems