File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .util .Arrays ;
2
+ import java .util .Scanner ;
3
+
4
+ public class Main {
5
+ public static void main (String [] args ) {
6
+ Scanner sc = new Scanner (System .in );
7
+
8
+ int t = sc .nextInt ();
9
+ for (int tc = 0 ; tc < t ; ++tc ) {
10
+ int n = sc .nextInt ();
11
+ int [] s = new int [n ];
12
+ for (int i = 0 ; i < s .length ; ++i ) {
13
+ s [i ] = sc .nextInt ();
14
+ }
15
+
16
+ System .out .println (solve (s ));
17
+ }
18
+
19
+ sc .close ();
20
+ }
21
+
22
+ static int solve (int [] s ) {
23
+ int [] maxLengths = new int [s .length ];
24
+ Arrays .fill (maxLengths , 1 );
25
+
26
+ for (int i = 0 ; i < maxLengths .length ; ++i ) {
27
+ for (int j = i * 2 + 1 ; j < maxLengths .length ; j += i + 1 ) {
28
+ if (s [j ] > s [i ]) {
29
+ maxLengths [j ] = Math .max (maxLengths [j ], maxLengths [i ] + 1 );
30
+ }
31
+ }
32
+ }
33
+
34
+ return Arrays .stream (maxLengths ).max ().getAsInt ();
35
+ }
36
+ }
You can’t perform that action at this time.
0 commit comments