Codeforces Round 1040 (Div. 1)

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
2129 Codeforces Round 1040 (Div. 1) FINISHED False 10800 22433123 July 31, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 16551 ) A Double Perspective PROGRAMMING constructive algorithms dp dsu greedy

For a set of pairs (S = \{(a_1, b_1), (a_2, b_2), \ldots, (a_m, b_m)\}), where (a_i < b_i) for all (1 \le i \le m), we define (f(S)) and (g(S)) as follows: Treating each ((a_i, b_i)) as a segment on the number line, (f(S)) is the length of their union. Formally, (f(S)) is the number of integers (x) such that there exists an (i) ((1 \leq i \leq m)) where (x, x+1 \subseteq a_i, b_i). Treating each ((a_i, b_i)) as an undirected edge in a graph, (g(S)) is the number of nodes that lie on at least one simple cycle with at least (3) edges. Formally, (g(S)) is the number of nodes (x_1) such that there exists a path (x_1 \to x_2 \to \ldots \to x_k \to x_1) in the graph, where (k \geq 3) and all (x_1, x_2, \ldots, x_k) are distinct. For example, (S = \{(1,2), (2,4), (1,4), (4,5),(6,7)\}), we can get (f(S) = 5) and (g(S) = 3). You are given (n) distinct pairs. Your task is to select a subset (S') of these pairs such that (f(S') - g(S')) is maximized. You need to output the indices of the selected pairs. 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 \le n \le 3 \cdot 10^3)). Next (n) lines each contain two integers (a_i) and (b_i) ((1 \le a_i < b_i \le 2n)), representing a pair. It is guaranteed that all pairs are distinct within the same test case. It is guaranteed that the sum of (n^2) over all test cases will not exceed (9 \cdot 10^6). For each test case, the first line contains an integer (k) ((0 \le k \le n)) — the size of the subset (S'). Next line contains (k) integers (i_1, i_2, \ldots, i_m) ((1 \le i_1 , i_2 , \ldots , i_k \le n)) — the indices of the selected pairs. Note the indices must be distinct . In the first test

Tutorials

Codeforces Round 1040 (Div. 1, Div. 2) Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
331756450 KumaTachiRen A July 31, 2025, 2:43 p.m. OK C# 13 TESTS 20 218 3072000
331756583 csp1025 A July 31, 2025, 2:43 p.m. OK C++17 (GCC 7-32) TESTS 20 109 307200
331884087 Hovery A Aug. 1, 2025, 1:27 a.m. OK C++17 (GCC 7-32) TESTS 20 124 102400
331774690 yangruibin1102 A July 31, 2025, 3 p.m. OK C++17 (GCC 7-32) TESTS 20 124 102400
331758383 weixin A July 31, 2025, 2:45 p.m. OK C++17 (GCC 7-32) TESTS 20 124 3276800
331768072 sunchaoyi A July 31, 2025, 2:53 p.m. OK C++17 (GCC 7-32) TESTS 20 125 0
331756854 Linear_B A July 31, 2025, 2:44 p.m. OK C++17 (GCC 7-32) TESTS 20 125 102400
331756323 yang114514 A July 31, 2025, 2:43 p.m. OK C++17 (GCC 7-32) TESTS 20 140 102400
331782789 crimson000 A July 31, 2025, 3:09 p.m. OK C++17 (GCC 7-32) TESTS 20 140 204800
331763998 Celebrate A July 31, 2025, 2:50 p.m. OK C++17 (GCC 7-32) TESTS 20 140 307200
331757371 as_dfsdf A July 31, 2025, 2:44 p.m. OK C++17 (GCC 7-32) TESTS 20 140 8192000
331755994 1234567st A July 31, 2025, 2:43 p.m. OK C++20 (GCC 13-64) TESTS 20 77 3481600
331755594 rgw2010 A July 31, 2025, 2:43 p.m. OK C++20 (GCC 13-64) TESTS 20 93 102400
331753292 Donaldqian0712 A July 31, 2025, 2:41 p.m. OK C++20 (GCC 13-64) TESTS 20 93 204800
331762172 Tom66 A July 31, 2025, 2:48 p.m. OK C++20 (GCC 13-64) TESTS 20 93 307200
331756998 Richard1211 A July 31, 2025, 2:44 p.m. OK C++20 (GCC 13-64) TESTS 20 93 2150400
331765125 systemStart A July 31, 2025, 2:51 p.m. OK C++20 (GCC 13-64) TESTS 20 93 20889600
331755438 ORzyzRO A July 31, 2025, 2:43 p.m. OK C++20 (GCC 13-64) TESTS 20 108 0
331758390 DiMashina2005 A July 31, 2025, 2:45 p.m. OK C++20 (GCC 13-64) TESTS 20 108 102400
331757203 fyable A July 31, 2025, 2:44 p.m. OK C++20 (GCC 13-64) TESTS 20 108 102400
331755205 Sanae A July 31, 2025, 2:42 p.m. OK C++20 (GCC 13-64) TESTS 20 108 102400
331748073 maspy A July 31, 2025, 2:37 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 307200
331757584 furry A July 31, 2025, 2:44 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 77 3174400
331768733 Leo_0503 A July 31, 2025, 2:54 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 93 204800
331764190 424479543 A July 31, 2025, 2:50 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 108 102400
331749469 exgcd A July 31, 2025, 2:38 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 108 102400
331755585 miscalculation53 A July 31, 2025, 2:43 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 108 307200
331891337 WhatIsHKOI A Aug. 1, 2025, 3:03 a.m. OK C++23 (GCC 14-64, msys2) TESTS 20 109 0
331788535 _ChiFAN_ A July 31, 2025, 3:17 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 109 102400
331759747 volochai A July 31, 2025, 2:46 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 109 102400
331757861 ShirayukiNoa A July 31, 2025, 2:45 p.m. OK C++23 (GCC 14-64, msys2) TESTS 20 109 102400
331757005 Gassa A July 31, 2025, 2:44 p.m. OK D TESTS 20 421 3379200
331766000 Cybuster A July 31, 2025, 2:51 p.m. OK D TESTS 20 436 2867200
331868976 Gassa A July 31, 2025, 8:46 p.m. OK D TESTS 20 499 3379200
331884294 IseriNina27 A Aug. 1, 2025, 1:30 a.m. OK GNU C11 TESTS 20 109 2252800
331763940 pengin_2000 A July 31, 2025, 2:50 p.m. OK GNU C11 TESTS 20 155 102400
331755135 blu_bird A July 31, 2025, 2:42 p.m. OK GNU C11 TESTS 20 1031 204800
331769232 Dominion948 A July 31, 2025, 2:54 p.m. OK Go TESTS 20 358 5120000
331758468 lyongwolf A July 31, 2025, 2:45 p.m. OK Java 21 TESTS 20 250 614400
331756409 iamalizaidi A July 31, 2025, 2:43 p.m. OK Java 21 TESTS 20 405 716800
331885101 man-ray A Aug. 1, 2025, 1:42 a.m. OK Java 21 TESTS 20 406 819200
331771219 finalboss_20 A July 31, 2025, 2:57 p.m. OK Java 21 TESTS 20 406 1126400
331752614 theSSS A July 31, 2025, 2:40 p.m. OK Java 21 TESTS 20 421 1331200
331759924 Lilypad A July 31, 2025, 2:46 p.m. OK Java 21 TESTS 20 468 409600
331837139 Quasicoherent A July 31, 2025, 4:46 p.m. OK Java 21 TESTS 20 515 1638400
331803784 rakshit2611 A July 31, 2025, 3:38 p.m. OK Java 21 TESTS 20 1468 1331200
331768973 Sincerely_yours A July 31, 2025, 2:54 p.m. OK Kotlin 1.9 TESTS 20 453 1740800
331764457 chinerist A July 31, 2025, 2:50 p.m. OK PyPy 3-64 TESTS 20 217 9625600
331758481 Mukundan314 A July 31, 2025, 2:45 p.m. OK PyPy 3-64 TESTS 20 218 9420800
331757517 bcollet A July 31, 2025, 2:44 p.m. OK PyPy 3-64 TESTS 20 218 25395200
331758496 harurun4635 A July 31, 2025, 2:45 p.m. OK PyPy 3-64 TESTS 20 249 9728000
331759150 kdy8128 A July 31, 2025, 2:45 p.m. OK PyPy 3-64 TESTS 20 327 9728000
331750805 dyppp A July 31, 2025, 2:39 p.m. OK PyPy 3-64 TESTS 20 327 10547200
331765295 x3x3 A July 31, 2025, 2:51 p.m. OK PyPy 3-64 TESTS 20 343 9318400
331750001 16777216 A July 31, 2025, 2:39 p.m. OK PyPy 3-64 TESTS 20 343 11264000
331758688 ThatOnePythonUser A July 31, 2025, 2:45 p.m. OK PyPy 3-64 TESTS 20 374 10137600
331753240 thewaxmango A July 31, 2025, 2:41 p.m. OK PyPy 3-64 TESTS 20 375 8704000
331752953 shanks_jr10 A July 31, 2025, 2:41 p.m. OK Python 3 TESTS 20 499 36761600
331752126 sansen A July 31, 2025, 2:40 p.m. OK Rust 2021 TESTS 20 77 512000
331755448 Sugar_fan A July 31, 2025, 2:43 p.m. OK Rust 2021 TESTS 20 108 409600
331752162 Egor A July 31, 2025, 2:40 p.m. OK Rust 2021 TESTS 20 109 0
331757291 DanielAnker A July 31, 2025, 2:44 p.m. OK Rust 2021 TESTS 20 155 102400
331751619 Ming_Xu A July 31, 2025, 2:40 p.m. OK Rust 2021 TESTS 20 156 102400

remove filters

Back to search problems