Codeforces Round 794 (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
1685 Codeforces Round 794 (Div. 1) FINISHED False 8100 78323099 May 25, 2022, 5:35 p.m.

Problems

Solved$
Index
Name
Type
Tags
Community Tag
Rating
( 108 ) D2 Permutation Weight (Hard Version) PROGRAMMING constructive algorithms greedy 3500

B"This is a hard version of the problem. The difference between the easy and hard versions is that in this version, you have to output the lexicographically smallest permutation with the smallest weight. You are given a permutation p_1, p_2, ldots, p_n of integers from 1 to n . Let's define the weight of the permutation q_1, q_2, ldots, q_n of integers from 1 to n as |q_1 - p_{q_{2}}| + |q_2 - p_{q_{3}}| + ldots + |q_{n-1} - p_{q_{n}}| + |q_n - p_{q_{1}}| You want your permutation to be as lightweight as possible. Among the permutations q with the smallest possible weight, find the lexicographically smallest. Permutation a_1, a_2, ldots, a_n is lexicographically smaller than permutation b_1, b_2, ldots, b_n , if there exists some 1 <= i <= n such that a_j = b_j for all 1 <= j < i and a_i<b_i . The first line of the input contains a single integer t ( 1 <= t <= 100 ) -- the number of test cases. The description of the test cases follows. The first line of each test case contains a single integer n ( 2 <= n <= 200 ) -- the size of the permutation. The second line of each test case contains n integers p_1, p_2, ldots, p_n ( 1 <= p_i <= n , all p_i are distinct) -- the elements of the permutation. The sum of n over all test cases doesn't exceed 400 . For each test case, output n integers q_1, q_2, ldots, q_n ( 1 <= q_i <= n , all q_i are distinct) -- the lexicographically smallest permutation with the smallest weight. In the first test case, there are two permutations of length 2 : (1, 2) and (2, 1) . Permutation (1, 2) has weight |1 - p_2| + |2 - p_1| = 0 , and the permutation (2, 1) has the same weight: |2 - p_1| + |1 - p_2| = 0 . In this version, you have to output the lexicographically smaller of them -- (1, 2) . In the seco"...

Tutorials

103198

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
158516814 YeongTree D2 May 26, 2022, 10:44 a.m. OK GNU C++17 TESTS 16 15 204800 3500
158561732 heno239 D2 May 26, 2022, 7:22 p.m. OK GNU C++17 TESTS 16 30 8908800 3500
158488941 sHaHriAr_17s D2 May 26, 2022, 4:30 a.m. OK GNU C++17 TESTS 16 46 307200 3500
158478636 Radewoosh D2 May 26, 2022, 12:10 a.m. OK GNU C++17 TESTS 16 93 204800 3500
158581379 errorgorn D2 May 27, 2022, 5:17 a.m. OK GNU C++17 (64) TESTS 16 15 921600 3500
158511890 anonymous_777 D2 May 26, 2022, 9:42 a.m. OK GNU C++17 (64) TESTS 16 15 66150400 3500
158450783 ecnerwala D2 May 25, 2022, 6:42 p.m. OK GNU C++17 (64) TESTS 16 30 0 3500
158467580 gamegame D2 May 25, 2022, 7:49 p.m. OK GNU C++20 (64) TESTS 16 15 66150400 3500
158467275 maroonrk D2 May 25, 2022, 7:48 p.m. OK GNU C++20 (64) TESTS 16 30 0 3500
158479754 emorgan5289 D2 May 26, 2022, 12:52 a.m. OK GNU C++20 (64) TESTS 16 31 0 3500
158457366 jiangly D2 May 25, 2022, 7:04 p.m. OK GNU C++20 (64) TESTS 16 31 0 3500

remove filters

Back to search problems