Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.121 s | 18 KBi |
#2 |
Correcto
|
0.132 s | 18 KBi |
#3 |
Correcto
|
0.133 s | 18 KBi |
#4 |
Incorrecto
|
0.121 s | 19 KBi |
#5 |
Correcto
|
0.117 s | 18 KBi |
#6 |
Correcto
|
0.095 s | 18 KBi |
#7 |
Error en tiempo de ejecución (NZEC)
Exited with error status 1 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 165534 out of bounds for length 150100 at Main.constructSA(Main.java:42) at Main.run(Main.java:138) at Main.main(Main.java:158) |
0.472 s | 23 KBi |
#8 |
Error en tiempo de ejecución (NZEC)
Exited with error status 1 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 150100 out of bounds for length 150100 at Main.constructSA(Main.java:42) at Main.run(Main.java:138) at Main.main(Main.java:158) |
0.524 s | 24 KBi |
#9 |
Error en tiempo de ejecución (NZEC)
Exited with error status 1 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 165523 out of bounds for length 150100 at Main.constructSA(Main.java:42) at Main.run(Main.java:138) at Main.main(Main.java:158) |
0.426 s | 24 KBi |
#10 |
Error en tiempo de ejecución (NZEC)
Exited with error status 1 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 165523 out of bounds for length 150100 at Main.constructSA(Main.java:42) at Main.run(Main.java:138) at Main.main(Main.java:158) |
0.439 s | 26 KBi |
#11 |
Correcto
|
0.457 s | 25 KBi |
#12 |
Error en tiempo de ejecución (NZEC)
Exited with error status 1 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 165116 out of bounds for length 150100 at Main.constructSA(Main.java:42) at Main.run(Main.java:138) at Main.main(Main.java:158) |
0.418 s | 24 KBi |
#13 |
Error en tiempo de ejecución (NZEC)
Exited with error status 1 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 165533 out of bounds for length 150100 at Main.constructSA(Main.java:42) at Main.run(Main.java:138) at Main.main(Main.java:158) |
0.472 s | 24 KBi |
#14 |
Error en tiempo de ejecución (NZEC)
Exited with error status 1 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 165533 out of bounds for length 150100 at Main.constructSA(Main.java:42) at Main.run(Main.java:138) at Main.main(Main.java:158) |
0.468 s | 25 KBi |
#15 |
Error en tiempo de ejecución (NZEC)
Exited with error status 1 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 165533 out of bounds for length 150100 at Main.constructSA(Main.java:42) at Main.run(Main.java:138) at Main.main(Main.java:158) |
0.492 s | 24 KBi |
#16 |
Correcto
|
0.431 s | 23 KBi |
#17 |
Correcto
|
0.602 s | 25 KBi |
#18 |
Correcto
|
0.772 s | 25 KBi |
#19 |
Incorrecto
|
0.755 s | 23 KBi |
#20 |
Incorrecto
|
0.676 s | 25 KBi |
#21 |
Correcto
|
0.651 s | 25 KBi |
#22 |
Error en tiempo de ejecución (NZEC)
Exited with error status 1 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: Index 165534 out of bounds for length 150100 at Main.constructSA(Main.java:42) at Main.run(Main.java:138) at Main.main(Main.java:158) |
0.48 s | 23 KBi |
import java.util.*; class Main { char T[]; int n; int[] RA, tempRA; Integer[] SA, tempSA; int[] c; char P[]; int m; int[] Phi; int[] PLCP; int[] LCP; void countingSort(int k) { int i, sum, maxi = Math.max(300, n); for (i = 0; i < 150100; i++) c[i] = 0; for (i = 0; i < n; i++) c[i + k < n ? RA[i + k] : 0]++; for (i = sum = 0; i < maxi; i++) { int t = c[i]; c[i] = sum; sum += t; } for (i = 0; i < n; i++) tempSA[c[SA[i] + k < n ? RA[SA[i] + k] : 0]++] = SA[i]; for (i = 0; i < n; i++) SA[i] = tempSA[i]; } void constructSA() { int i, k, r; for (i = 0; i < n; i++) RA[i] = T[i]; for (i = 0; i < n; i++) SA[i] = i; for (k = 1; k < n; k <<= 1) { countingSort(k); countingSort(0); tempRA[SA[0]] = r = 0; for (i = 1; i < n; i++) tempRA[SA[i]] = (RA[SA[i]] == RA[SA[i-1]] && RA[SA[i]+k] == RA[SA[i-1]+k]) ? r : ++r; for (i = 0; i < n; i++) RA[i] = tempRA[i]; } } void computeLCP() { int i, L; Phi[SA[0]] = -1; for (i = 1; i < n; i++) Phi[SA[i]] = SA[i-1]; for (i = L = 0; i < n; i++) { if (Phi[i] == -1) { PLCP[i] = 0; continue; } while (i + L < T.length && Phi[i] + L < T.length && T[i + L] == T[Phi[i] + L]) L++; PLCP[i] = L; L = Math.max(L-1, 0); } for (i = 1; i < n; i++) LCP[i] = PLCP[SA[i]]; } int strncmp(char[] a, int i, char[] b, int j, int n){ for (int k=0; i+k < a.length && j+k < b.length; k++){ if (a[i+k] != b[j+k]) return a[i+k] - b[j+k]; } return 0; } int[] stringMatching() { int lo = 0, hi = n-1, mid = lo; while (lo < hi) { mid = (lo + hi) / 2; int res = strncmp(T, SA[mid], P, 0, m); if (res >= 0) hi = mid; else lo = mid + 1; } if (strncmp(T,SA[lo], P,0, m) != 0) return new int[]{-1, -1}; int[] ans = new int[]{ lo, 0} ; lo = 0; hi = n - 1; mid = lo; while (lo < hi) { mid = (lo + hi) / 2; int res = strncmp(T, SA[mid], P,0, m); if (res > 0) hi = mid; else lo = mid + 1; } if (strncmp(T, SA[hi], P,0, m) != 0) hi--; ans[1] = hi; return ans; } void LRS() { int i, idx = 0, maxLCP = 0; for (i = 1; i < n; i++) if (LCP[i] > maxLCP) { maxLCP = LCP[i]; idx = i; } } int owner(int idx) { return (idx < n-m-1) ? 1 : 2; } int getBorder() { int n = T.length; int res = -1; for(int i = 0; i < n; i += 1) { if(SA[i] == 0) { res = i; break; } } int i = res; while(i > 0 && n - SA[i - 1] != LCP[i]) { i -= 1; } if(i <= 0 || (n - SA[i - 1]) != LCP[i]) { return -1; } else { return LCP[i]; } } void run(String s) { int MAX_N = 150100; c = new int[MAX_N]; RA = new int[MAX_N]; tempRA = new int[MAX_N]; SA = new Integer[MAX_N]; tempSA = new Integer[MAX_N]; Phi = new int[MAX_N]; PLCP = new int[MAX_N]; LCP = new int[MAX_N]; T = s.toCharArray(); n = T.length; constructSA(); computeLCP(); int i = getBorder(); if(i == -1) { System.out.println(0); } else { System.out.println(i); } /*for(int i = 0; i < T.length; i += 1) { System.out.println(SA[i] + " " + LCP[i]); }*/ } public static void main(String[] args){ Scanner scan = new Scanner(System.in); new Main().run(scan.nextLine()); } }