Kotlin Heroes: Episode 11

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
2011 Kotlin Heroes: Episode 11 FINISHED False 9000 48785084 Sept. 30, 2024, 2:35 p.m.

Problems

Solved
Index
Name
Type
Tags
Community Tag
Rating
( 131 ) F Good Subarray PROGRAMMING *special data structures greedy

You are given an integer array (a) of size (n). Let's call an array good if it can be obtained using the following algorithm: create an array consisting of any single integer; and then perform the following operation an arbitrary number of times: choose an element from the already existing array (let's call it (x)) and add (x), ((x-1)), or ((x+1)) to the end of the array. For example, the arrays (1, 2, 1), (5) and (3, 2, 1, 4) are good, while (2, 4) and (3, 1, 2) are not. Your task is to count the number of good contiguous subarrays of the array (a). Two subarrays that have the same elements but are in different positions of the array (a) are considered different. 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 3 \cdot 10^5)). The second line of each test case contains (n) integers (a_1, a_2, \dots, a_n) ((1 \le a_i \le n)). Additional constraint on the input: the sum of (n) over all test cases does not exceed (3 \cdot 10^5). For each test case, print a single integer — the number of good contiguous subarrays of the array (a). In the first example, the following four subarrays are good: from the (1)-st to the (1)-st element; from the (1)-st to the (2)-nd element; from the (2)-nd to the (2)-nd element; from the (3)-rd to the (3)-rd element. In the second example, the only subarray which is not good is the subarray from the (3)-rd element to the (4)-th element.

Tutorials

Kotlin Heroes 11 — Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
283782231 Ra16bit F Sept. 30, 2024, 3:15 p.m. OK Kotlin 1.7 TESTS 18 671 130150400
283789882 abcde34534 F Sept. 30, 2024, 4:01 p.m. OK Kotlin 1.7 TESTS 18 687 82534400
283804033 tokitsukaze F Sept. 30, 2024, 5:31 p.m. OK Kotlin 1.7 TESTS 18 703 117657600
283791396 nguyenhoangminh318 F Sept. 30, 2024, 4:11 p.m. OK Kotlin 1.7 TESTS 18 781 163737600
283784709 ttamx F Sept. 30, 2024, 3:30 p.m. OK Kotlin 1.7 TESTS 18 827 122982400
283782687 wsyear F Sept. 30, 2024, 3:18 p.m. OK Kotlin 1.7 TESTS 18 827 143052800
283793549 WiwiHo F Sept. 30, 2024, 4:24 p.m. OK Kotlin 1.7 TESTS 18 843 190566400
283789119 Yae-Miko F Sept. 30, 2024, 3:56 p.m. OK Kotlin 1.7 TESTS 18 858 175923200
283784580 IsaacMoris F Sept. 30, 2024, 3:29 p.m. OK Kotlin 1.7 TESTS 18 874 177766400
283835771 Sparkle_Twilight F Oct. 1, 2024, 1:28 a.m. OK Kotlin 1.7 TESTS 18 921 150016000
283790285 Slamur F Sept. 30, 2024, 4:04 p.m. OK Kotlin 1.9 TESTS 18 359 18944000
283791028 nuip F Sept. 30, 2024, 4:08 p.m. OK Kotlin 1.9 TESTS 18 374 21196800
283795133 sd0061 F Sept. 30, 2024, 4:34 p.m. OK Kotlin 1.9 TESTS 18 406 9216000
283784052 errorgorn F Sept. 30, 2024, 3:26 p.m. OK Kotlin 1.9 TESTS 18 421 24268800
283788829 yudedako F Sept. 30, 2024, 3:55 p.m. OK Kotlin 1.9 TESTS 18 421 25804800
283779726 tourist F Sept. 30, 2024, 3:01 p.m. OK Kotlin 1.9 TESTS 18 421 25804800
283786719 Kude F Sept. 30, 2024, 3:42 p.m. OK Kotlin 1.9 TESTS 18 452 25907200
283780573 Tlatoani F Sept. 30, 2024, 3:05 p.m. OK Kotlin 1.9 TESTS 18 452 29081600
283816941 MiinaMagdy F Sept. 30, 2024, 7:09 p.m. OK Kotlin 1.9 TESTS 18 484 28467200
283779729 arvindf232 F Sept. 30, 2024, 3:01 p.m. OK Kotlin 1.9 TESTS 18 484 61952000

remove filters

Back to search problems