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'This is the easy version of the problem. The only difference between the two versions are the allowed characters in s . In the easy version, s only contains the character ?. You can make hacks only if both versions of the problem are solved. You are given a permutation p of length n . You are also given a string s of length n , consisting only of the character ?. For each i from 1 to n : Initially, you have an undirected graph with n vertices (numbered from 1 to n ) and no edges. Then, for each i from 1 to n , add one edge to the graph: Find the maximum possible diameter ^{ text{ xe2 x88 x97}} over all connected graphs that you can form. Output -1 if it is not possible to form any connected graphs. ^{ text{ xe2 x88 x97}} Let d(s, t) denote the smallest number of edges on any path between s and t . The diameter of the graph is defined as the maximum value of d(s, t) over all pairs of vertices s and t . Each test contains multiple test cases. The first line of input contains a single integer t ( 1 <= t <= 2 cdot 10^4 ) -- 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 <= 4 cdot 10^5 ) -- the length of the permutation p . The second line of each test case contains n integers p_1,p_2, ldots, p_n ( 1 <= p_i <= n ) -- the elements of p , which are guaranteed to form a permutation. The third line of each test case contains a string s of length n . It is guaranteed that it consists only of the character ?. It is guaranteed that the sum of n over all test cases does not exceed 4 cdot 10^5 . For each test case, output the maximum possible diameter over all connected graphs that you form, or -1 if it is not possible to form any connected graphs. In the first test case, h'... |
Tutorials
Submissions
Submission Id |
Author(s) |
Index |
Submitted |
Verdict |
Language |
Test Set |
Tests Passed |
Time taken (ms) |
Memory Consumed (bytes) |
Tags |
Rating |
268256518 |
deerbefree |
G1 |
July 1, 2024, 3:26 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
143 |
186 |
29184000 |
|
|
268211386 |
StarSilk |
G1 |
June 30, 2024, 5:08 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
143 |
187 |
26214400 |
|
|
268257699 |
deerbefree |
G1 |
July 1, 2024, 3:42 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
143 |
202 |
25907200 |
|
|
268209781 |
E_fireworks |
G1 |
June 30, 2024, 5:03 p.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
143 |
218 |
27136000 |
|
|
268257031 |
zhouhuanyi |
G1 |
July 1, 2024, 3:33 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
143 |
249 |
30310400 |
|
|
268250225 |
houzhiyuan_1234 |
G1 |
July 1, 2024, 1:48 a.m. |
OK |
C++14 (GCC 6-32) |
TESTS |
143 |
702 |
81408000 |
|
|
268243907 |
yutabi |
G1 |
June 30, 2024, 11:25 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
187 |
12083200 |
|
|
268267713 |
Sparkle_Twilight |
G1 |
July 1, 2024, 5:41 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
187 |
31539200 |
|
|
268267490 |
taiwanguo |
G1 |
July 1, 2024, 5:39 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
187 |
31539200 |
|
|
268265032 |
theRealChainman |
G1 |
July 1, 2024, 5:12 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
202 |
11468800 |
|
|
268257508 |
NKheyuxiang |
G1 |
July 1, 2024, 3:39 a.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
202 |
25497600 |
|
|
268210639 |
potato167 |
G1 |
June 30, 2024, 5:05 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
249 |
53145600 |
|
|
268213830 |
zzpc |
G1 |
June 30, 2024, 5:16 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
312 |
59187200 |
|
|
268216105 |
Kilani |
G1 |
June 30, 2024, 5:23 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
328 |
49254400 |
|
|
268231031 |
amirhoseinfar1385 |
G1 |
June 30, 2024, 7:39 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
452 |
131481600 |
|
|
268230968 |
amirhoseinfar1385 |
G1 |
June 30, 2024, 7:38 p.m. |
OK |
C++17 (GCC 7-32) |
TESTS |
143 |
453 |
131379200 |
|
|
268250482 |
yangster67 |
G1 |
July 1, 2024, 1:53 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
171 |
9011200 |
|
|
268253007 |
yangster67 |
G1 |
July 1, 2024, 2:36 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
171 |
9113600 |
|
|
268217288 |
PinkieRabbit |
G1 |
June 30, 2024, 5:26 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
171 |
18534400 |
|
|
268251300 |
sg78276397 |
G1 |
July 1, 2024, 2:08 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
187 |
15872000 |
|
|
268213609 |
BurnedChicken |
G1 |
June 30, 2024, 5:15 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
187 |
48025600 |
|
|
268217663 |
BNDStxdy |
G1 |
June 30, 2024, 5:27 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
187 |
126259200 |
|
|
268214606 |
CJ_xde_pt |
G1 |
June 30, 2024, 5:18 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
187 |
152576000 |
|
|
268260072 |
your_submissions_ |
G1 |
July 1, 2024, 4:11 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
202 |
56115200 |
|
|
268257074 |
UdtaDegen_11 |
G1 |
July 1, 2024, 3:34 a.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
202 |
56115200 |
|
|
268208359 |
CJ-zhuyifan |
G1 |
June 30, 2024, 4:58 p.m. |
OK |
C++20 (GCC 13-64) |
TESTS |
143 |
234 |
62873600 |
|
|
remove filters
Back to search problems