Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.204 s | 13 KBi |
#2 |
Correcto
|
0.187 s | 13 KBi |
#3 |
Correcto
|
0.201 s | 13 KBi |
#4 |
Correcto
|
0.2 s | 13 KBi |
#5 |
Correcto
|
0.173 s | 13 KBi |
#6 |
Correcto
|
0.182 s | 13 KBi |
#7 |
Correcto
|
0.398 s | 18 KBi |
#8 |
Correcto
|
0.349 s | 19 KBi |
#9 |
Correcto
|
0.382 s | 18 KBi |
#10 |
Correcto
|
0.358 s | 18 KBi |
#11 |
Correcto
|
0.364 s | 18 KBi |
#12 |
Correcto
|
0.356 s | 17 KBi |
#13 |
Correcto
|
0.406 s | 19 KBi |
#14 |
Correcto
|
0.396 s | 17 KBi |
#15 |
Correcto
|
0.363 s | 18 KBi |
#16 |
Correcto
|
0.375 s | 18 KBi |
#17 |
Correcto
|
0.402 s | 18 KBi |
#18 |
Correcto
|
0.358 s | 19 KBi |
#19 |
Correcto
|
0.371 s | 18 KBi |
#20 |
Correcto
|
0.393 s | 18 KBi |
#21 |
Correcto
|
0.36 s | 18 KBi |
#22 |
Correcto
|
0.354 s | 18 KBi |
import java.util.Scanner; class Main{ public static void main(String[] args) { Scanner sc = new Scanner(System.in); String s = sc.nextLine(); sc.close(); int n = s.length(); int arr[] = new int[n]; int pos = 0; for (int i = 1; i < n; i++) { while (s.charAt(i) != s.charAt(pos) && pos > 0) { pos = arr[pos - 1]; } if (s.charAt(i) == s.charAt(pos)) { pos++; } arr[i] = pos; } System.out.println(arr[n - 1]); } }