Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Incorrecto
|
0.114 s | 17 KBi |
#2 |
Incorrecto
|
0.091 s | 17 KBi |
#3 |
Incorrecto
|
0.102 s | 16 KBi |
#4 |
Incorrecto
|
0.121 s | 18 KBi |
#5 |
Incorrecto
|
0.091 s | 17 KBi |
#6 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.429 s | 125 KBi |
#7 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.467 s | 125 KBi |
#8 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.51 s | 125 KBi |
#9 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.514 s | 125 KBi |
#10 |
Error en tiempo de ejecución (NZEC)
Exited with error status 137 run: line 1: 3 Killed /usr/local/openjdk13/bin/java Main |
0.484 s | 125 KBi |
import java.util.HashMap; import java.util.Scanner; public class Main { private static HashMap<Integer, Integer> memoization = new HashMap<Integer, Integer>(); public static void main(String[] args) { Scanner scanner = new Scanner(System.in); int casosDePrueba = scanner.nextInt(); for(int caso=0; caso<casosDePrueba; caso++){ int n = scanner.nextInt(); int[] array = new int[n]; for(int i=0; i<n; i++){ array[i]=scanner.nextInt(); } findMaxSuffixArray(0, array); StringBuilder stringBuilder = new StringBuilder(); stringBuilder.append("Case #" +caso +":"); for(int i=0; i<n; i++){ int value = array[i]; int horizon = findMaxSuffixArray(i+1, array); if(value>=horizon){ stringBuilder.append(" -1"); } else { stringBuilder.append(" " + horizon); } } System.out.println(stringBuilder); memoization = new HashMap<Integer, Integer>(); } } private static int findMaxSuffixArray(int start, int[] array){ if(memoization.containsKey(start)){ return memoization.get(start); } if(start == array.length){ memoization.put(start, -1); return -1; } int value = array[start]; int recResponse = findMaxSuffixArray(start+1, array); int max = Math.max(value, recResponse); memoization.put(start, max); return max; } }