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.
Problems
B'Polycarp is playing a new computer game. This game has n stones in a row. The stone on the position i has integer power a_i . The powers of all stones are distinct. Each turn Polycarp can destroy either stone on the first position or stone on the last position (in other words, either the leftmost or the rightmost stone). When Polycarp destroys the stone it does not exist any more. Now, Polycarp wants two achievements. He gets them if he destroys the stone with the least power and the stone with the greatest power. Help Polycarp find out what is the minimum number of moves he should make in order to achieve his goal. For example, if n = 5 and a = [1, 5, 4, 3, 2] , then Polycarp could make the following moves: Please note that in the example above, you can complete the game in two steps. For example: The first line contains an integer t ( 1 <= t <= 100 ). Then t test cases follow. The first line of each test case contains one integer n ( 2 <= n <= 100 ) -- the number of stones. The second line contains n distinct integers a_1, a_2, ldots, a_n ( 1 <= a_i <= n ) -- the power of the stones. For each test case, output the minimum number of moves required to destroy the stones with the greatest and the lowest power. '... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
119109327 |
gikihog |
A |
June 11, 2021, 3 a.m. |
OK |
Clang++17 Diagnostics |
TESTS |
6 |
46 |
1024000 |
|
|
119094644 |
2020akadaver |
A |
June 10, 2021, 7:41 p.m. |
OK |
Clang++17 Diagnostics |
TESTS |
5 |
62 |
0 |
|
|
119094528 |
2020akadaver |
A |
June 10, 2021, 7:39 p.m. |
OK |
Clang++17 Diagnostics |
TESTS |
5 |
78 |
0 |
|
|
119114339 |
Sham_Devour |
A |
June 11, 2021, 4:29 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119113778 |
kartikey104 |
A |
June 11, 2021, 4:20 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119119548 |
stilldazy |
A |
June 11, 2021, 5:40 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119119278 |
GAME__ON |
A |
June 11, 2021, 5:37 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119119237 |
kjasir23 |
A |
June 11, 2021, 5:36 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119118929 |
prashanth_64 |
A |
June 11, 2021, 5:32 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119115891 |
V_K_S_ |
A |
June 11, 2021, 4:52 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119115695 |
ywx2002 |
A |
June 11, 2021, 4:49 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119115310 |
Wuyanru |
A |
June 11, 2021, 4:43 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119114991 |
codeocean233 |
A |
June 11, 2021, 4:39 a.m. |
OK |
GNU C++11 |
TESTS |
6 |
15 |
0 |
|
|
119102252 |
HA_Team |
A |
June 10, 2021, 10:54 p.m. |
OK |
GNU C++14 |
TESTS |
6 |
0 |
0 |
|
|
119118702 |
SreemukhMantri |
A |
June 11, 2021, 5:30 a.m. |
OK |
GNU C++14 |
TESTS |
6 |
15 |
0 |
|
|
119119037 |
pretending |
A |
June 11, 2021, 5:34 a.m. |
OK |
GNU C++14 |
TESTS |
6 |
15 |
0 |
|
|
119118842 |
NEON_10 |
A |
June 11, 2021, 5:31 a.m. |
OK |
GNU C++14 |
TESTS |
6 |
15 |
0 |
|
|
119120868 |
Mani007 |
A |
June 11, 2021, 5:56 a.m. |
OK |
GNU C++14 |
TESTS |
6 |
15 |
0 |
|
|
119120575 |
abhishek.gururani |
A |
June 11, 2021, 5:52 a.m. |
OK |
GNU C++14 |
TESTS |
6 |
15 |
0 |
|
|
119120321 |
Abhishek123sin |
A |
June 11, 2021, 5:49 a.m. |
OK |
GNU C++14 |
TESTS |
6 |
15 |
0 |
|
|
119119928 |
raportii |
A |
June 11, 2021, 5:44 a.m. |
OK |
GNU C++14 |
TESTS |
6 |
15 |
0 |
|
|
119119916 |
Anshikamishra |
A |
June 11, 2021, 5:44 a.m. |
OK |
GNU C++14 |
TESTS |
6 |
15 |
0 |
|
|
119119888 |
jamiyashwanth18 chakri_007_ |
A |
June 11, 2021, 5:44 a.m. |
OK |
GNU C++14 |
TESTS |
6 |
15 |
0 |
|
|
119110737 |
navam19314 |
A |
June 11, 2021, 3:27 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
0 |
102400 |
|
|
119105213 |
YSJY |
A |
June 11, 2021, 1:13 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
0 |
409600 |
|
|
119120299 |
harshit_18 |
A |
June 11, 2021, 5:49 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
15 |
0 |
|
|
119120578 |
Ngu_ |
A |
June 11, 2021, 5:52 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
15 |
0 |
|
|
119120411 |
PrateekShakya |
A |
June 11, 2021, 5:50 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
15 |
0 |
|
|
119121320 |
iota_i |
A |
June 11, 2021, 6:01 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
15 |
0 |
|
|
119121200 |
tanujvats |
A |
June 11, 2021, 6 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
15 |
0 |
|
|
119121184 |
Fliahin |
A |
June 11, 2021, 5:59 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
15 |
0 |
|
|
119121138 |
cocp_mwoct |
A |
June 11, 2021, 5:59 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
15 |
0 |
|
|
119120836 |
hey_ankit |
A |
June 11, 2021, 5:55 a.m. |
OK |
GNU C++17 |
TESTS |
6 |
15 |
0 |
|
|
119106773 |
Ahad726 |
A |
June 11, 2021, 2:02 a.m. |
OK |
.NET Core C# |
TESTS |
6 |
93 |
819200 |
|
|
119105707 |
Ahad726 |
A |
June 11, 2021, 1:29 a.m. |
OK |
.NET Core C# |
TESTS |
6 |
108 |
1024000 |
|
|
remove filters
Back to search problems