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
( 941 ) D Permutation Blackhole PROGRAMMING combinatorics dp

For a permutation (p_1, p_2, \ldots, p_n) of length (n), the corresponding coloring sequence (s) can be obtained by the following coloring process: Initially, there are (n) white cells indexed from (1) to (n) from left to right. At second (0), the score of each cell is (0). At second (i) ((1 \le i \le n)), If (i > 1), find the nearest black cell to the cell (p_i), and increase the score of that cell by (1). In case there are multiple nearest black cells, choose the cell with the lowest index. Cell (y) is called the nearest black cell to cell (x) only if cell (y) is black and there is no black cell (z) satisfying (|x-z|<|x-y|). Color the cell (p_i) black. If (i > 1), find the nearest black cell to the cell (p_i), and increase the score of that cell by (1). In case there are multiple nearest black cells, choose the cell with the lowest index. Cell (y) is called the nearest black cell to cell (x) only if cell (y) is black and there is no black cell (z) satisfying (|x-z|<|x-y|). Color the cell (p_i) black. After all cells are colored black, denoting (s_i) as the score of cell (i) ((1 \le i \le n)), we get the coloring sequence (s). You might want to read the notes for a better understanding. You are given an incomplete coloring sequence (s), where some (s_i) are already fixed, while others are not yet determined. Count how many different permutations (p) can produce this coloring sequence. Since the answer may be large, you need to output it modulo (998\,244\,353). Each test contains multiple test cases. The first line contains the number of test cases (t) ((1 \le t \le 10^3)). The description of the test cases follows. For each test case, the first line contains an integer (n) ((2 \leq n \leq 100)). The second line contains (n) integers (s_1, s_2, \ldots, s_n) ((-1 \leq s_i \leq n-1)). Here

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
331878109 Celebrate D Aug. 1, 2025, 12:11 a.m. OK C++17 (GCC 7-32) TESTS 93 78 5939200
331872926 kalimm D July 31, 2025, 9:53 p.m. OK C++17 (GCC 7-32) TESTS 93 93 42905600
331822918 a2514631360 D July 31, 2025, 4:13 p.m. OK C++17 (GCC 7-32) TESTS 93 109 10035200
331820597 grass8sheep D July 31, 2025, 4:08 p.m. OK C++17 (GCC 7-32) TESTS 93 139 102400
331853062 ben-ustc D July 31, 2025, 5:28 p.m. OK C++17 (GCC 7-32) TESTS 93 218 102400
331896201 wind_cross D Aug. 1, 2025, 3:58 a.m. OK C++17 (GCC 7-32) TESTS 93 312 487219200
331866505 man_of_learning D July 31, 2025, 8:18 p.m. OK C++17 (GCC 7-32) TESTS 93 342 487219200
331833431 AiPd D July 31, 2025, 4:36 p.m. OK C++17 (GCC 7-32) TESTS 93 343 70144000
331878395 KroosTheKeenGlint D Aug. 1, 2025, 12:17 a.m. OK C++17 (GCC 7-32) TESTS 93 375 10035200
331808527 Crystally D July 31, 2025, 3:46 p.m. OK C++17 (GCC 7-32) TESTS 93 437 27648000
331849504 makrav D July 31, 2025, 5:19 p.m. OK C++20 (GCC 13-64) TESTS 93 77 102400
331868527 surajchip2 D July 31, 2025, 8:41 p.m. OK C++20 (GCC 13-64) TESTS 93 77 20070400
331904569 sheep32768 D Aug. 1, 2025, 5:45 a.m. OK C++20 (GCC 13-64) TESTS 93 77 487219200
331839450 rgw2010 D July 31, 2025, 4:52 p.m. OK C++20 (GCC 13-64) TESTS 93 93 409600
331838115 Revived_xryjr233 D July 31, 2025, 4:48 p.m. OK C++20 (GCC 13-64) TESTS 93 93 409600
331905995 ashishc1 D Aug. 1, 2025, 6 a.m. OK C++20 (GCC 13-64) TESTS 93 93 9318400
331815139 yeminghan D July 31, 2025, 3:57 p.m. OK C++20 (GCC 13-64) TESTS 93 93 10752000
331829449 Xylenox D July 31, 2025, 4:27 p.m. OK C++20 (GCC 13-64) TESTS 93 108 5427200
331827955 bingpao D July 31, 2025, 4:23 p.m. OK C++20 (GCC 13-64) TESTS 93 108 17408000
331855790 wangmarui D July 31, 2025, 5:34 p.m. OK C++20 (GCC 13-64) TESTS 93 108 21094400
331837653 JDScript0117 D July 31, 2025, 4:47 p.m. OK C++23 (GCC 14-64, msys2) TESTS 93 77 409600
331896532 tobias.glimmerfors D Aug. 1, 2025, 4:02 a.m. OK C++23 (GCC 14-64, msys2) TESTS 93 77 3891200
331905429 amsraman D Aug. 1, 2025, 5:54 a.m. OK C++23 (GCC 14-64, msys2) TESTS 93 78 0
331894272 fishcathu D Aug. 1, 2025, 3:37 a.m. OK C++23 (GCC 14-64, msys2) TESTS 93 92 3174400
331796702 YuJiahe D July 31, 2025, 3:28 p.m. OK C++23 (GCC 14-64, msys2) TESTS 93 92 4505600
331827040 gloria_mundi D July 31, 2025, 4:21 p.m. OK C++23 (GCC 14-64, msys2) TESTS 93 93 102400
331825510 ecnerwala D July 31, 2025, 4:18 p.m. OK C++23 (GCC 14-64, msys2) TESTS 93 93 1433600
331867035 slah007 D July 31, 2025, 8:24 p.m. OK C++23 (GCC 14-64, msys2) TESTS 93 93 11161600
331832049 seanlsy D July 31, 2025, 4:33 p.m. OK C++23 (GCC 14-64, msys2) TESTS 93 93 11366400
331809063 strapple D July 31, 2025, 3:47 p.m. OK C++23 (GCC 14-64, msys2) TESTS 93 93 27750400
331874761 Quasicoherent D July 31, 2025, 10:38 p.m. OK Java 21 TESTS 93 468 19251200
331901836 conqueror_of_tourist D Aug. 1, 2025, 5:13 a.m. OK PyPy 3-64 TESTS 93 1186 23654400
331846898 Egor D July 31, 2025, 5:12 p.m. OK Rust 2021 TESTS 93 124 14643200
331836426 sansen D July 31, 2025, 4:44 p.m. OK Rust 2021 TESTS 93 359 512000
331839621 DanielAnker D July 31, 2025, 4:52 p.m. OK Rust 2021 TESTS 93 874 2969600
331844323 Sugar_fan D July 31, 2025, 5:05 p.m. OK Rust 2021 TESTS 93 890 1638400

remove filters

Back to search problems