Educational Codeforces Round 182 (Rated for Div. 2)

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
2144 Educational Codeforces Round 182 (Rated for Div. 2) FINISHED False 7200 18458723 Sept. 15, 2025, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 18358 ) B Maximum Cost Permutation PROGRAMMING constructive algorithms greedy

Recall that a permutation of length (n) is a sequence of length (n) such that each integer from (1) to (n) appears in it exactly once. Let's define the cost of a permutation as the minimum length of its contiguous subsegment (possibly empty) that needs to be sorted so that the entire permutation becomes sorted in ascending order. You are given an integer array (p) consisting of integers from (0) to (n), where no positive (strictly greater than zero) integer appears more than once. You should replace zeros with integers so that the array (p) becomes a permutation. Your task is to calculate the maximum possible cost of the resulting permutation. The first line contains a single integer (t) ((1 \le t \le 10^4)) — the number of test cases. The first line of each test case contains a single integer (n) ((1 \le n \le 2 \cdot 10^5)). The second line contains (n) integers (p_1, p_2, \dots, p_n) ((0 \le p_i \le n)). No positive integer appears more than once in this sequence. Additional constraint on the input: the sum of (n) over all test cases doesn't exceed (2 \cdot 10^5). For each test case, print a single integer — the maximum possible cost of the resulting permutation. In the first example, you can make a permutation (1, 3, 4, 2, 5) with the cost (3), because you have to sort segment (2, 4). In the second example, you can make a permutation (2, 3, 1) with the cost (3), because you have to sort segment (1, 3). In the third example, there is only one possible permutation — (1, 2, 3, 4), with the cost (0), because the permutation is already sorted. In the fourth example, there is only one possible permutation — (1, 3, 2), with the cost (2), because you have to sort segment (2, 3).

Tutorials

Educational Codeforces Round 182 Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
338876480 og.kostya B Sept. 16, 2025, 7:31 a.m. OK C# 10 TESTS 18 109 2252800
338876316 og.kostya B Sept. 16, 2025, 7:30 a.m. OK C# 13 TESTS 18 140 2048000
338838916 abdellah1234 B Sept. 15, 2025, 8:47 p.m. OK C# 13 TESTS 18 155 33792000
338831758 mahmudur9 B Sept. 15, 2025, 7:09 p.m. OK C# 13 TESTS 18 296 33484800
338940239 _usan B Sept. 16, 2025, 2:51 p.m. OK C++17 (GCC 7-32) TESTS 18 62 0
338820894 adityashukla.sun B Sept. 15, 2025, 5:28 p.m. OK C++17 (GCC 7-32) TESTS 18 62 0
339026492 IResh B Sept. 17, 2025, 5:15 a.m. OK C++17 (GCC 7-32) TESTS 18 77 0
339019313 Divyansh1128 B Sept. 17, 2025, 3:27 a.m. OK C++17 (GCC 7-32) TESTS 18 77 0
339009551 Phantom_R B Sept. 17, 2025, 12:38 a.m. OK C++17 (GCC 7-32) TESTS 18 77 0
338987538 TheQuestionMark B Sept. 16, 2025, 6:09 p.m. OK C++17 (GCC 7-32) TESTS 18 77 0
338969861 shreyasshinde600 B Sept. 16, 2025, 5:07 p.m. OK C++17 (GCC 7-32) TESTS 18 77 0
338950479 Chinmay_Kulkarni_Codes B Sept. 16, 2025, 3:58 p.m. OK C++17 (GCC 7-32) TESTS 18 77 0
338939188 Mhd9011 B Sept. 16, 2025, 2:45 p.m. OK C++17 (GCC 7-32) TESTS 18 77 0
338939062 Abraham_Barrett B Sept. 16, 2025, 2:44 p.m. OK C++17 (GCC 7-32) TESTS 18 77 0
338877520 ACE0172 B Sept. 16, 2025, 7:41 a.m. OK C++20 (GCC 13-64) TESTS 18 46 3072000
339027220 theReddy1 B Sept. 17, 2025, 5:25 a.m. OK C++20 (GCC 13-64) TESTS 18 62 0
339025837 croman_77 B Sept. 17, 2025, 5:04 a.m. OK C++20 (GCC 13-64) TESTS 18 62 0
339024669 croman_77 B Sept. 17, 2025, 4:47 a.m. OK C++20 (GCC 13-64) TESTS 18 62 0
339014284 Aaronli2 B Sept. 17, 2025, 2:28 a.m. OK C++20 (GCC 13-64) TESTS 18 62 0
339011820 you-jin-plus B Sept. 17, 2025, 1:33 a.m. OK C++20 (GCC 13-64) TESTS 18 62 0
339006457 xorman B Sept. 16, 2025, 10:51 p.m. OK C++20 (GCC 13-64) TESTS 18 62 0
338988923 AndreyKhodyrev B Sept. 16, 2025, 6:21 p.m. OK C++20 (GCC 13-64) TESTS 18 62 0
338953256 Nomia B Sept. 16, 2025, 4:16 p.m. OK C++20 (GCC 13-64) TESTS 18 62 0
338924679 mikasa-yue B Sept. 16, 2025, 1:15 p.m. OK C++20 (GCC 13-64) TESTS 18 62 0
338935382 YMWL B Sept. 16, 2025, 2:20 p.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 0
338905507 halfpast5 B Sept. 16, 2025, 11:17 a.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 0
338889446 Masterer B Sept. 16, 2025, 9:04 a.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 0
338848419 alkayesrifat B Sept. 16, 2025, 12:32 a.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 0
338847501 genshin-expert B Sept. 16, 2025, 12:10 a.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 0
338826797 tin.le2 B Sept. 15, 2025, 6:19 p.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 0
338822891 Nirupam B Sept. 15, 2025, 5:45 p.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 0
338955638 tfg B Sept. 16, 2025, 4:35 p.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 102400
338935702 mimingucci B Sept. 16, 2025, 2:22 p.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 102400
338850861 journeyCowsHu B Sept. 16, 2025, 1:28 a.m. OK C++23 (GCC 14-64, msys2) TESTS 18 62 102400
338877714 Gnaneswar_K B Sept. 16, 2025, 7:43 a.m. OK GNU C11 TESTS 18 77 1740800
338862510 love_gold_ B Sept. 16, 2025, 4:47 a.m. OK GNU C11 TESTS 18 77 45158400
338836901 uffhottie B Sept. 15, 2025, 8:14 p.m. OK Go TESTS 18 92 12492800
338827856 Dyejkstra B Sept. 15, 2025, 6:28 p.m. OK Go TESTS 18 1015 5120000
339021738 ruhan.habib39 B Sept. 17, 2025, 3:58 a.m. OK Haskell TESTS 18 234 30412800
338841311 tekka_ity B Sept. 15, 2025, 9:30 p.m. OK Java 21 TESTS 18 264 2252800
338849228 sakshamjain08 B Sept. 16, 2025, 12:52 a.m. OK Java 21 TESTS 18 265 1536000
338910892 lupunish B Sept. 16, 2025, 11:50 a.m. OK Java 21 TESTS 18 280 204800
338989614 Azad_Singh B Sept. 16, 2025, 6:28 p.m. OK Java 21 TESTS 18 280 512000
338995543 Tharun_Reddy_ B Sept. 16, 2025, 7:26 p.m. OK Java 21 TESTS 18 281 409600
338945470 ujjwaltwitx B Sept. 16, 2025, 3:27 p.m. OK Java 21 TESTS 18 281 7475200
338877919 IvyReverie B Sept. 16, 2025, 7:45 a.m. OK Java 21 TESTS 18 296 819200
338988790 vanshpal921 B Sept. 16, 2025, 6:20 p.m. OK Java 21 TESTS 18 312 512000
338839763 Java_Coder B Sept. 15, 2025, 9:02 p.m. OK Java 21 TESTS 18 312 3993600
338833827 faizparvez B Sept. 15, 2025, 7:33 p.m. OK Java 21 TESTS 18 327 10547200
338818146 amre_8800 B Sept. 15, 2025, 5:07 p.m. OK Java 8 TESTS 18 156 0
338832624 Ashu2030 B Sept. 15, 2025, 7:18 p.m. OK Java 8 TESTS 18 187 2662400
338833033 abhayrajnegi0416 B Sept. 15, 2025, 7:23 p.m. OK Java 8 TESTS 18 202 3276800
338833873 sarthaKKharKa_18 B Sept. 15, 2025, 7:33 p.m. OK Java 8 TESTS 18 218 12800000
338986117 multibagger B Sept. 16, 2025, 5:57 p.m. OK Java 8 TESTS 18 249 13312000
338843813 suntansoker B Sept. 15, 2025, 10:25 p.m. OK Java 8 TESTS 18 296 14540800
338824431 y_a_s B Sept. 15, 2025, 5:58 p.m. OK Java 8 TESTS 18 358 17203200
338906496 21omkatyarmal B Sept. 16, 2025, 11:24 a.m. OK Java 8 TESTS 18 374 0
338910987 vivek_6987 B Sept. 16, 2025, 11:50 a.m. OK Java 8 TESTS 18 389 0
338837035 code_manik B Sept. 15, 2025, 8:16 p.m. OK Java 8 TESTS 18 405 3481600
338838781 aolive505 B Sept. 15, 2025, 8:45 p.m. OK JavaScript TESTS 18 156 19763200
338826602 L-S-S B Sept. 15, 2025, 6:18 p.m. OK Kotlin 2.2 TESTS 18 296 14438400
338835623 konni35 B Sept. 15, 2025, 7:56 p.m. OK Kotlin 2.2 TESTS 18 311 14540800
338990174 swseverance B Sept. 16, 2025, 6:33 p.m. OK Node.js TESTS 18 265 56320000
338901871 hasangiyosov603 B Sept. 16, 2025, 10:47 a.m. OK PyPy 3 TESTS 18 327 16179200
338846891 mega_mango B Sept. 15, 2025, 11:54 p.m. OK PyPy 3 TESTS 18 359 14540800
338984040 SreenathReddyk B Sept. 16, 2025, 5:39 p.m. OK PyPy 3 TESTS 18 374 14438400
338925488 VivirAstucia B Sept. 16, 2025, 1:20 p.m. OK PyPy 3-64 TESTS 18 140 22425600
338854844 chan120714 B Sept. 16, 2025, 2:45 a.m. OK PyPy 3-64 TESTS 18 140 25497600
338838950 explainer B Sept. 15, 2025, 8:48 p.m. OK PyPy 3-64 TESTS 18 155 22528000
338914845 alexwice B Sept. 16, 2025, 12:12 p.m. OK PyPy 3-64 TESTS 18 156 22630400
338819550 paneerpulao B Sept. 15, 2025, 5:18 p.m. OK PyPy 3-64 TESTS 18 171 22528000
338819265 gardengnome B Sept. 15, 2025, 5:16 p.m. OK PyPy 3-64 TESTS 18 171 24064000
338877166 Om_Singh_ B Sept. 16, 2025, 7:38 a.m. OK PyPy 3-64 TESTS 18 171 24576000
338822226 Nrmn-ali B Sept. 15, 2025, 5:39 p.m. OK PyPy 3-64 TESTS 18 171 26931200
338952480 1Not B Sept. 16, 2025, 4:11 p.m. OK PyPy 3-64 TESTS 18 171 33177600
338895330 Tz1934 B Sept. 16, 2025, 9:47 a.m. OK PyPy 3-64 TESTS 18 187 22528000
338842702 tanhjklove B Sept. 15, 2025, 10 p.m. OK Python 3 TESTS 18 155 22220800
338819902 Bakytz7zaN B Sept. 15, 2025, 5:21 p.m. OK Python 3 TESTS 18 155 22630400
338828619 mohanmrm20 B Sept. 15, 2025, 6:36 p.m. OK Python 3 TESTS 18 155 24064000
339012356 igobysani B Sept. 17, 2025, 1:45 a.m. OK Python 3 TESTS 18 156 21094400
338901747 FyReX_KING635 B Sept. 16, 2025, 10:46 a.m. OK Python 3 TESTS 18 156 24371200
338921272 mithra.09 B Sept. 16, 2025, 12:54 p.m. OK Python 3 TESTS 18 156 27033600
338816808 mdisharaf B Sept. 15, 2025, 4:58 p.m. OK Python 3 TESTS 18 171 20992000
338899804 Tetralix B Sept. 16, 2025, 10:28 a.m. OK Python 3 TESTS 18 171 22630400
338852888 phtniit B Sept. 16, 2025, 2:11 a.m. OK Python 3 TESTS 18 171 22732800
339015567 ren95943 B Sept. 17, 2025, 2:44 a.m. OK Python 3 TESTS 18 171 24371200
338857184 Svlad_Cjelli B Sept. 16, 2025, 3:25 a.m. OK Rust 2021 TESTS 18 46 819200
338944228 alexis_g_alba B Sept. 16, 2025, 3:18 p.m. OK Rust 2024 TESTS 18 61 921600
339019970 La_Liability B Sept. 17, 2025, 3:35 a.m. OK Rust 2024 TESTS 18 62 0

remove filters

Back to search problems