Codeforces Round 841 (Div. 2) and Divide by Zero 2022

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
1731 Codeforces Round 841 (Div. 2) and Divide by Zero 2022 FINISHED False 7200 65028263 Dec. 27, 2022, 2:35 p.m.

Problems

Solved$
Index
Name
Type
Tags
Community Tag
Rating
( 2940 ) E Graph Cost PROGRAMMING dp greedy math number theory

B"You are given an initially empty undirected graph with n nodes, numbered from 1 to n (i. e. n nodes and 0 edges). You want to add m edges to the graph, so the graph won't contain any self-loop or multiple edges. If an edge connecting two nodes u and v is added, its weight must be equal to the greatest common divisor of u and v , i. e. gcd(u, v) . In order to add edges to the graph, you can repeat the following process any number of times (possibly zero): For example, if you can add 5 more edges to the graph of weight 6 , you may add them, and it will cost 6 for the whole pack of 5 edges. But if you can only add 4 edges of weight 6 to the graph, you can't perform this operation for k = 5 . Given two integers n and m , find the minimum total cost to form a graph of n vertices and exactly m edges using the operation above. If such a graph can't be constructed, output -1 . Note that the final graph may consist of several connected components. Each test contains multiple test cases. The first line contains the number of test cases t ( 1 <= q t <= q 10^4 ). Description of the test cases follows. The first line of each test case contains two integers n and m ( 2 <= q n <= q 10^6 ; 1 <= q m <= q frac{n(n-1)}{2} ). It is guaranteed that the sum of n over all test cases does not exceed 10^6 . For each test case, print the minimum cost to build the graph, or -1 if you can't build such a graph. In the first test case, we can add an edge between the vertices 2 and 4 with gcd = 2 . This is the only possible way to add 1 edge that will cost 2 . In the second test case, there is no way to add 10 edges, so the answer is -1 . In the third test case, we can add the following edges: "...

Tutorials

Codeforces Round #841 (Div. 2) and Divide By Zero 2022 Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
187034122 Tyranno E Dec. 28, 2022, 12:23 p.m. OK GNU C++14 TESTS 47 31 12288000
187026913 HuaKeJiZhe E Dec. 28, 2022, 11:08 a.m. OK GNU C++14 TESTS 47 31 21094400
187034435 Tyranno E Dec. 28, 2022, 12:27 p.m. OK GNU C++14 TESTS 47 46 12288000
187404485 Gaode_Sean E Dec. 31, 2022, 4:21 a.m. OK GNU C++14 TESTS 47 46 16076800
187440419 02Darling E Dec. 31, 2022, 11:39 a.m. OK GNU C++14 TESTS 47 46 21094400
187207894 zzhrnoicansolve E Dec. 30, 2022, 6 a.m. OK GNU C++14 TESTS 47 46 22118400
187400336 JackWei E Dec. 31, 2022, 2:46 a.m. OK GNU C++14 TESTS 47 46 24064000
187154973 xiaobottle E Dec. 29, 2022, 2:59 p.m. OK GNU C++14 TESTS 47 46 24064000
187117440 Shrich E Dec. 29, 2022, 8:52 a.m. OK GNU C++14 TESTS 47 46 34099200
187135000 binyufang E Dec. 29, 2022, 11:56 a.m. OK GNU C++14 TESTS 47 61 21094400
187157315 dredwerkz E Dec. 29, 2022, 3:21 p.m. OK GNU C++17 TESTS 47 46 6041600
187443280 yqq E Dec. 31, 2022, 12:12 p.m. OK GNU C++17 TESTS 47 46 17408000
187203465 jiangzimi2008 E Dec. 30, 2022, 4:46 a.m. OK GNU C++17 TESTS 47 46 20070400
187200773 Haven_ E Dec. 30, 2022, 3:47 a.m. OK GNU C++17 TESTS 47 46 24064000
187490969 SkadiTheCorruptingHeart E Jan. 1, 2023, 3:40 a.m. OK GNU C++17 TESTS 47 61 16076800
187199774 Haven_ E Dec. 30, 2022, 3:23 a.m. OK GNU C++17 TESTS 47 61 24064000
187223378 lazyhash E Dec. 30, 2022, 9:12 a.m. OK GNU C++17 TESTS 47 62 3993600
187130038 kursharss E Dec. 29, 2022, 11:07 a.m. OK GNU C++17 TESTS 47 62 3993600
187092913 angrybird7090 E Dec. 29, 2022, 2:23 a.m. OK GNU C++17 TESTS 47 62 3993600
187157836 dredwerkz E Dec. 29, 2022, 3:26 p.m. OK GNU C++17 TESTS 47 62 6041600
187187260 rondoudou E Dec. 29, 2022, 8:57 p.m. OK GNU C++17 (64) TESTS 47 31 3993600
187057860 CurryWOE E Dec. 28, 2022, 4:29 p.m. OK GNU C++17 (64) TESTS 47 31 4198400
187056791 CurryWOE E Dec. 28, 2022, 4:17 p.m. OK GNU C++17 (64) TESTS 47 46 9113600
187027809 DogSeven E Dec. 28, 2022, 11:18 a.m. OK GNU C++17 (64) TESTS 47 46 16998400
187128664 Once_I_Liked_AGirl E Dec. 29, 2022, 10:54 a.m. OK GNU C++17 (64) TESTS 47 46 17203200
187099414 ExplodingKonjac E Dec. 29, 2022, 5 a.m. OK GNU C++17 (64) TESTS 47 46 18124800
187092061 llzzxx712 E Dec. 29, 2022, 1:56 a.m. OK GNU C++17 (64) TESTS 47 46 24883200
187130696 Once_I_Liked_AGirl E Dec. 29, 2022, 11:13 a.m. OK GNU C++17 (64) TESTS 47 61 17203200
187034958 Jieneng E Dec. 28, 2022, 12:32 p.m. OK GNU C++17 (64) TESTS 47 61 40038400
187380459 NanZaaa E Dec. 30, 2022, 6:50 p.m. OK GNU C++17 (64) TESTS 47 62 16384000
187045931 inzamam_inz E Dec. 28, 2022, 2:25 p.m. OK GNU C++20 (64) TESTS 47 31 3993600
187039152 Gaurav3478 E Dec. 28, 2022, 1:25 p.m. OK GNU C++20 (64) TESTS 47 46 3993600
187175711 Serendipity__ E Dec. 29, 2022, 6:15 p.m. OK GNU C++20 (64) TESTS 47 46 12083200
187063710 TravellingSalesman E Dec. 28, 2022, 5:28 p.m. OK GNU C++20 (64) TESTS 47 46 12083200
187489385 Proofy E Jan. 1, 2023, 2:39 a.m. OK GNU C++20 (64) TESTS 47 46 16179200
187489367 Proofy E Jan. 1, 2023, 2:38 a.m. OK GNU C++20 (64) TESTS 47 46 16179200
187489330 Proofy E Jan. 1, 2023, 2:37 a.m. OK GNU C++20 (64) TESTS 47 46 16998400
187157806 XiCen E Dec. 29, 2022, 3:25 p.m. OK GNU C++20 (64) TESTS 47 46 16998400
187252091 zzwtz2333 E Dec. 30, 2022, 2:26 p.m. OK GNU C++20 (64) TESTS 47 46 20070400
187094057 Licykoc E Dec. 29, 2022, 2:55 a.m. OK GNU C++20 (64) TESTS 47 46 21299200
187097842 wdjuruo E Dec. 29, 2022, 4:31 a.m. OK Java 11 TESTS 47 326 7680000
187081893 daftdove E Dec. 28, 2022, 9:12 p.m. OK Java 11 TESTS 47 373 6963200
187494687 nodal_tree E Jan. 1, 2023, 5:29 a.m. OK Java 11 TESTS 47 389 6860800
187391115 ziduoyi E Dec. 30, 2022, 9:31 p.m. OK Java 11 TESTS 47 530 45465600
187093925 Eslam_Ahmed E Dec. 29, 2022, 2:51 a.m. OK Java 17 TESTS 47 280 8294400
187157206 HeyHello2 E Dec. 29, 2022, 3:20 p.m. OK Java 8 TESTS 47 249 5734400
187249727 duckladydinh E Dec. 30, 2022, 2:03 p.m. OK Kotlin 1.7 TESTS 47 421 24064000
187028450 xhchen E Dec. 28, 2022, 11:25 a.m. OK MS C++ 2017 TESTS 47 139 7987200
187202235 fatant E Dec. 30, 2022, 4:22 a.m. OK MS C++ 2017 TESTS 47 156 7987200
187028015 chinesedfan E Dec. 28, 2022, 11:20 a.m. OK Node.js TESTS 47 373 83251200
187126438 YMSeah E Dec. 29, 2022, 10:31 a.m. OK PyPy 3 TESTS 47 545 26214400
187188339 1_2_3_4_5_9 E Dec. 29, 2022, 9:20 p.m. OK PyPy 3 TESTS 47 1153 31744000
187126139 big_aL E Dec. 29, 2022, 10:28 a.m. OK PyPy 3-64 TESTS 47 155 10444800
187233865 suncup224 E Dec. 30, 2022, 11:14 a.m. OK PyPy 3-64 TESTS 47 186 20889600
187065873 big_aL E Dec. 28, 2022, 5:50 p.m. OK PyPy 3-64 TESTS 47 202 10444800
187089191 RobinFromTheHood E Dec. 29, 2022, 12:01 a.m. OK PyPy 3-64 TESTS 47 358 10854400
187117182 NINGucas E Dec. 29, 2022, 8:49 a.m. OK PyPy 3-64 TESTS 47 373 13414400
187089162 RobinFromTheHood E Dec. 29, 2022, midnight OK PyPy 3-64 TESTS 47 374 11366400
187123170 NINGucas E Dec. 29, 2022, 9:55 a.m. OK PyPy 3-64 TESTS 47 374 58368000
187201485 Benq E Dec. 30, 2022, 4:03 a.m. OK Rust 2021 TESTS 47 171 24064000

remove filters

Back to search problems