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 |
|---|---|---|---|---|---|---|
| 2119 | Codeforces Round 1035 (Div. 2) | FINISHED | False | 7200 | 24679522 | July 5, 2025, 2:35 p.m. |
Solved |
Index |
Name |
Type |
Tags |
Community Tag |
Rating |
|---|---|---|---|---|---|---|
| ( 698 ) | E | And Constraint | PROGRAMMING | bitmasks dp greedy implementation |
You are given a sequence (a) of length (n-1) and a sequence (b) of length (n). You can perform the following operation any number of times (possibly zero): choose an index (1 \le i \le n) and increment (b_i) by (1) (i.e., set (b_i \leftarrow b_i + 1)). Your goal is to perform the minimum number of operations such that for every (1 \le i \le n-1), the condition (b_i \, \& \, b_{i+1} = a_i) holds, where (\&) denotes the bitwise AND operation . If it is impossible to satisfy the condition, report it as well. 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 contains a single integer (n) ((2 \le n \le 10^5)). The second line contains (n-1) integers (a_1, a_2, \ldots, a_{n-1}) ((0 \le a_i < 2^{29})). The third line contains (n) integers (b_1, b_2, \ldots, b_n) ((0 \le b_i < 2^{29})). It is guaranteed that the sum of (n) over all test cases does not exceed (2\cdot 10^5). For each test case, you need to output only one integer. If the goal can be achieved, output one integer — the minimum number of operations required. Otherwise, output (-1). In the first test case, one of the optimal strategies is to use (4) operations to make (b = 1,5,4,4), which satisfies all the conditions. We can prove that it is impossible to use fewer than (4) operations. In the second test case, since (b_1 \, \& \, b_2 = 4) and (b_2 \, \& \, b_3 =0), then (b_3 \, \& \, 4 =0). However, we require that (b_3 \, \& \, b_4 =4), which means it is impossible to satisfy all the conditions. |
| Codeforces Round 1035 (Div. 2) Editorial |
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
|---|---|---|---|---|---|---|---|---|---|---|---|
| 327658195 | KumaTachiRen | E | July 6, 2025, 1:23 a.m. | OK | C# 13 | TESTS | 36 | 452 | 12390400 | ||
| 327629273 | _Nyusha_ | E | July 5, 2025, 5:38 p.m. | OK | C++17 (GCC 7-32) | TESTS | 36 | 577 | 55398400 | ||
| 327626230 | walizamanee | E | July 5, 2025, 5:17 p.m. | OK | C++17 (GCC 7-32) | TESTS | 36 | 577 | 58777600 | ||
| 327637857 | _odium | E | July 5, 2025, 6:51 p.m. | OK | C++17 (GCC 7-32) | TESTS | 36 | 593 | 117043200 | ||
| 327627391 | jayPrakashkumar | E | July 5, 2025, 5:25 p.m. | OK | C++17 (GCC 7-32) | TESTS | 36 | 858 | 52736000 | ||
| 327627746 | octane | E | July 5, 2025, 5:27 p.m. | OK | C++17 (GCC 7-32) | TESTS | 36 | 1015 | 58572800 | ||
| 327634540 | thangdz2k7 | E | July 5, 2025, 6:21 p.m. | OK | C++17 (GCC 7-32) | TESTS | 36 | 1031 | 27545600 | ||
| 327629362 | Good_WeekDay_ | E | July 5, 2025, 5:39 p.m. | OK | C++17 (GCC 7-32) | TESTS | 36 | 1686 | 88268800 | ||
| 327665097 | turkhuu622 | E | July 6, 2025, 3:36 a.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 265 | 819200 | ||
| 327631126 | TRDOG | E | July 5, 2025, 5:53 p.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 280 | 56217600 | ||
| 327634587 | CReatiQ | E | July 5, 2025, 6:21 p.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 312 | 102400 | ||
| 327649472 | justin_zed | E | July 5, 2025, 9:10 p.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 374 | 38604800 | ||
| 327658589 | cqrcqr | E | July 6, 2025, 1:34 a.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 390 | 62054400 | ||
| 327640488 | thisislike_fan | E | July 5, 2025, 7:13 p.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 406 | 102400 | ||
| 327624821 | 111445 | E | July 5, 2025, 5:08 p.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 421 | 38502400 | ||
| 327654612 | zltzlt | E | July 5, 2025, 11:26 p.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 421 | 58982400 | ||
| 327625630 | Misuki | E | July 5, 2025, 5:13 p.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 452 | 23654400 | ||
| 327624313 | Nana7ni | E | July 5, 2025, 5:05 p.m. | OK | C++20 (GCC 13-64) | TESTS | 36 | 452 | 64614400 | ||
| 327634898 | tempura0224 | E | July 5, 2025, 6:24 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 374 | 23142400 | ||
| 327651402 | Boboge | E | July 5, 2025, 9:52 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 374 | 41881600 | ||
| 327635023 | tempura0224 | E | July 5, 2025, 6:25 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 405 | 22528000 | ||
| 327639969 | phsads | E | July 5, 2025, 7:08 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 452 | 102400 | ||
| 327635636 | vedantkohad | E | July 5, 2025, 6:30 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 453 | 0 | ||
| 327625722 | real_man | E | July 5, 2025, 5:13 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 484 | 49766400 | ||
| 327624566 | Nrtusea | E | July 5, 2025, 5:06 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 499 | 54784000 | ||
| 327639195 | UFEQ | E | July 5, 2025, 7:02 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 515 | 102400 | ||
| 327634489 | realcomplex | E | July 5, 2025, 6:21 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 515 | 51916800 | ||
| 327637947 | UFEQ | E | July 5, 2025, 6:52 p.m. | OK | C++23 (GCC 14-64, msys2) | TESTS | 36 | 531 | 29593600 | ||
| 327639337 | ayushkumar991890 | E | July 5, 2025, 7:03 p.m. | OK | GNU C11 | TESTS | 36 | 421 | 54988800 | ||
| 327649304 | lyongwolf | E | July 5, 2025, 9:07 p.m. | OK | Java 21 | TESTS | 36 | 1499 | 39424000 | ||
| 327651896 | golomb | E | July 5, 2025, 10:06 p.m. | OK | PyPy 3-64 | TESTS | 36 | 1217 | 59289600 | ||
| 327660047 | darkkcyan | E | July 6, 2025, 2:11 a.m. | OK | Rust 2021 | TESTS | 36 | 671 | 10342400 |
Back to search problems