Codeforces Round 1085 (Div. 1 + 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
2207 Codeforces Round 1085 (Div. 1 + Div. 2) FINISHED False 10800 3425123 March 8, 2026, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 5116 ) C Where's My Water? PROGRAMMING data structures divide and conquer implementation

Let (n, h) be positive integers. Swampy the Alligator needs water for his bathtub, and you are tasked with getting it to him. Above his house, there is an (h \times n) grid of dirt and water tiles with (n) columns numbered (1, \ldots, n). In column (i), the bottom (a_i) tiles are dirt, and the rest on top are water tiles. To get water to Swampy, you can place a drain on any tile that isn't a dirt tile. Placing a drain takes away all water tiles that can access the drain by moving only down, left, or right on the grid without crossing any dirt tiles. For example, placing the drain on the (\times) in the grid below will drain both the top left and top right water tiles and result in (10) tiles being drained: What is the maximum amount of water you can get to Swampy after placing at most two drains? Note that water tiles that could have been taken by either drain are only counted once. 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. The first line contains two integers (n) and (h) ((1 \leq n \leq 2000, 1 \leq h \leq 10^9)) — the number of columns and height of the grid. The next line contains (n) integers (a_i) ((1 \leq a_i \leq h)) — the elevation of the dirt in column (i). It is guaranteed that the sum of (n) over all test cases does not exceed (2000). For each test case, output a single integer — the maximum number of water tiles that can be obtained with at most two drains. In the first test case, the grid is the example shown in the statement. It is possible to drain (14) tiles of water by placing the drains as shown: In the second test case, the grid is shown below: It is possible to drain all (43) tiles of water by placing the drains as shown: In the third test case, the grid is a single dirt tile, and no drains may be placed. So, the answer is (0).

Tutorials

Codeforces Round 1085 (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
365943498 shanxizeng C March 9, 2026, 6:04 a.m. OK C++17 (GCC 7-32) TESTS 18 31 0
365922582 Dr.LindaMartin C March 8, 2026, 10:09 p.m. OK C++17 (GCC 7-32) TESTS 17 31 0
365900211 Re06741math C March 8, 2026, 5:25 p.m. OK C++17 (GCC 7-32) TESTS 17 31 0
365899676 imran67 C March 8, 2026, 5:22 p.m. OK C++17 (GCC 7-32) TESTS 17 31 0
365895395 hemangkhurana C March 8, 2026, 4:57 p.m. OK C++17 (GCC 7-32) TESTS 17 31 0
365881899 Arielzz C March 8, 2026, 3:46 p.m. OK C++17 (GCC 7-32) TESTS 17 31 0
365883490 xingtiankai2023 C March 8, 2026, 3:54 p.m. OK C++17 (GCC 7-32) TESTS 17 31 102400
365880894 dajeff C March 8, 2026, 3:41 p.m. OK C++17 (GCC 7-32) TESTS 17 31 102400
365937159 Trumpsunderwear C March 9, 2026, 4:22 a.m. OK C++17 (GCC 7-32) TESTS 17 31 1638400
365942196 landerpen C March 9, 2026, 5:48 a.m. OK C++17 (GCC 7-32) TESTS 18 46 0
365915250 gum-gum_no-mi_model-NIKA C March 8, 2026, 8:14 p.m. OK C++20 (GCC 13-64) TESTS 17 31 0
365893429 FelixMP C March 8, 2026, 4:46 p.m. OK C++20 (GCC 13-64) TESTS 17 31 0
365889664 sury666 C March 8, 2026, 4:25 p.m. OK C++20 (GCC 13-64) TESTS 17 31 0
365887958 Rakib...123 C March 8, 2026, 4:16 p.m. OK C++20 (GCC 13-64) TESTS 17 31 0
365886708 PACTBOPOB C March 8, 2026, 4:09 p.m. OK C++20 (GCC 13-64) TESTS 17 31 0
365882677 Rukiya C March 8, 2026, 3:50 p.m. OK C++20 (GCC 13-64) TESTS 17 31 0
365934112 lxllxs C March 9, 2026, 3:21 a.m. OK C++20 (GCC 13-64) TESTS 17 31 102400
365933743 lxllxs C March 9, 2026, 3:13 a.m. OK C++20 (GCC 13-64) TESTS 17 31 102400
365933461 mahiro_zcy C March 9, 2026, 3:07 a.m. OK C++20 (GCC 13-64) TESTS 17 31 102400
365929771 Synthia C March 9, 2026, 1:26 a.m. OK C++20 (GCC 13-64) TESTS 17 31 102400
365934097 Juvla C March 9, 2026, 3:21 a.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365928599 A7md_Sob7 C March 9, 2026, 12:50 a.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365923479 ziara1 C March 8, 2026, 10:30 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365911616 Wobert C March 8, 2026, 7:29 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365910014 szpu_ark C March 8, 2026, 7:09 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365905524 joacru C March 8, 2026, 6:14 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365901081 cslgZ09124102 C March 8, 2026, 5:29 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365900060 iamAditya-Pandey C March 8, 2026, 5:24 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365898419 rajpookie C March 8, 2026, 5:14 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365898225 7etem C March 8, 2026, 5:13 p.m. OK C++23 (GCC 14-64, msys2) TESTS 17 31 0
365897795 NenadDapic C March 8, 2026, 5:11 p.m. OK FPC TESTS 17 234 48332800
365887859 actualtsg C March 8, 2026, 4:15 p.m. OK GNU C11 TESTS 17 31 0
365925060 vvvDrew C March 8, 2026, 11:08 p.m. OK GNU C11 TESTS 17 31 102400
365932645 actualtsg C March 9, 2026, 2:47 a.m. OK GNU C11 TESTS 17 31 204800
365879689 EROR C March 8, 2026, 3:36 p.m. OK Go TESTS 17 46 102400
365907895 Ayush_Chauhan025 C March 8, 2026, 6:41 p.m. OK Java 21 TESTS 17 218 1740800
365896156 abdullabohra790 C March 8, 2026, 5:01 p.m. OK Java 21 TESTS 17 218 2048000
365898895 _MShadow_ C March 8, 2026, 5:17 p.m. OK Java 21 TESTS 17 234 512000
365890194 Preetham_22 C March 8, 2026, 4:28 p.m. OK Java 21 TESTS 17 234 512000
365893650 loadedcode C March 8, 2026, 4:47 p.m. OK Java 21 TESTS 17 234 614400
365883355 aha C March 8, 2026, 3:53 p.m. OK Java 21 TESTS 17 234 1024000
365881454 code_manik C March 8, 2026, 3:44 p.m. OK Java 21 TESTS 17 234 1024000
365880590 Dhanesh_K C March 8, 2026, 3:40 p.m. OK Java 21 TESTS 17 234 1536000
365892194 Ayush_Chauhan025 C March 8, 2026, 4:39 p.m. OK Java 21 TESTS 17 250 307200
365886227 lfg_sahil C March 8, 2026, 4:07 p.m. OK Java 21 TESTS 17 250 409600
365891590 nishulpatni2 C March 8, 2026, 4:35 p.m. OK Java 8 TESTS 17 140 0
365887988 Uday-B C March 8, 2026, 4:16 p.m. OK Java 8 TESTS 17 140 0
365885802 tohoshinki254 C March 8, 2026, 4:05 p.m. OK Java 8 TESTS 17 156 0
365907700 kamranm C March 8, 2026, 6:39 p.m. OK Java 8 TESTS 17 187 222412800
365888501 bindusreeA C March 8, 2026, 4:19 p.m. OK Java 8 TESTS 17 468 77107200
365887462 HmmBro12 C March 8, 2026, 4:13 p.m. OK Java 8 TESTS 17 562 150220800
365886550 Ayush79 C March 8, 2026, 4:09 p.m. OK Kotlin 2.2 TESTS 17 156 23859200
365882676 nullbrain_ C March 8, 2026, 3:50 p.m. OK Kotlin 2.2 TESTS 17 187 42700800
365890820 xxxtentaclez C March 8, 2026, 4:31 p.m. OK Kotlin 2.2 TESTS 17 203 26828800
365884467 yg.margo C March 8, 2026, 3:58 p.m. OK Kotlin 2.2 TESTS 17 328 146022400
365889793 bu_gye_jeong C March 8, 2026, 4:25 p.m. OK Node.js TESTS 17 203 5529600
365889627 SanjarAlgo C March 8, 2026, 4:24 p.m. OK PascalABC.NET TESTS 17 484 101580800
365894827 wamachine_ C March 8, 2026, 4:54 p.m. OK PHP TESTS 17 62 4300800
365914209 bcollet C March 8, 2026, 8:01 p.m. OK PyPy 2 TESTS 17 125 2662400
365894407 mehalpandkar C March 8, 2026, 4:52 p.m. OK PyPy 3 TESTS 17 203 3788800
365896031 Jyotier C March 8, 2026, 5:01 p.m. OK PyPy 3 TESTS 17 281 7680000
365886182 WaffleMan C March 8, 2026, 4:07 p.m. OK PyPy 3 TESTS 17 843 68096000
365923554 ep268gza C March 8, 2026, 10:32 p.m. OK PyPy 3-64 TESTS 17 93 2560000
365929571 RobinFromTheHood C March 9, 2026, 1:20 a.m. OK PyPy 3-64 TESTS 17 93 3174400
365899675 mashirosama C March 8, 2026, 5:22 p.m. OK PyPy 3-64 TESTS 17 93 15872000
365904822 m.anav_dbz07 C March 8, 2026, 6:07 p.m. OK PyPy 3-64 TESTS 17 93 19456000
365922151 hxu10 C March 8, 2026, 10 p.m. OK PyPy 3-64 TESTS 17 109 2457600
365915653 artem. C March 8, 2026, 8:20 p.m. OK PyPy 3-64 TESTS 17 109 3481600
365906081 _ARYA_ C March 8, 2026, 6:20 p.m. OK PyPy 3-64 TESTS 17 109 3788800
365927992 Kartikey07 C March 9, 2026, 12:31 a.m. OK PyPy 3-64 TESTS 17 109 4710400
365927014 nasasmurf C March 9, 2026, 12:01 a.m. OK PyPy 3-64 TESTS 17 109 4710400
365893853 hugoback01 C March 8, 2026, 4:48 p.m. OK PyPy 3-64 TESTS 17 109 16281600
365898558 Jimanbanashi C March 8, 2026, 5:15 p.m. OK Python 2 TESTS 17 250 0
365881743 Ibrohim_2014 C March 8, 2026, 3:45 p.m. OK Python 3 TESTS 17 62 921600
365896163 Monish2000 C March 8, 2026, 5:01 p.m. OK Python 3 TESTS 17 187 18124800
365910961 mmaraltanan C March 8, 2026, 7:22 p.m. OK Python 3 TESTS 17 703 204800
365916824 Soultaker C March 8, 2026, 8:35 p.m. OK Python 3 TESTS 17 750 307200
365882768 alok_chandra01 C March 8, 2026, 3:50 p.m. OK Python 3 TESTS 17 812 1228800
365891407 BurningUFO C March 8, 2026, 4:34 p.m. OK Python 3 TESTS 17 828 409600
365896591 z1san C March 8, 2026, 5:04 p.m. OK Python 3 TESTS 17 937 102400
365888879 mudanvit.goyal C March 8, 2026, 4:20 p.m. OK Python 3 TESTS 17 968 204800
365888452 Varunkumar-01 C March 8, 2026, 4:18 p.m. OK Python 3 TESTS 17 1046 1536000
365906046 ZERO_HIKARI C March 8, 2026, 6:19 p.m. OK Python 3 TESTS 17 1109 1331200
365885200 hachiko2026 C March 8, 2026, 4:02 p.m. OK Ruby 3 TESTS 17 1546 2150400
365894632 davidmiheev C March 8, 2026, 4:53 p.m. OK Rust 2024 TESTS 17 31 11776000
365887253 DanielAnker C March 8, 2026, 4:12 p.m. OK Rust 2024 TESTS 17 31 11776000
365889005 SnowballSH C March 8, 2026, 4:21 p.m. OK Rust 2024 TESTS 17 46 11776000
365897410 _JG_ C March 8, 2026, 5:09 p.m. OK Rust 2024 TESTS 17 125 11776000
365887163 Shr1mp_ C March 8, 2026, 4:12 p.m. OK Rust 2024 TESTS 17 125 145305600
365884843 Darknef C March 8, 2026, 4 p.m. OK Rust 2024 TESTS 17 156 76185600

remove filters

Back to search problems