Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Error de compilación
Compilation time limit exceeded. |
||
#2 |
Error de compilación
Compilation time limit exceeded. |
||
#3 |
Error de compilación
Compilation time limit exceeded. |
||
#4 |
Error de compilación
Compilation time limit exceeded. |
||
#5 |
Correcto
|
0.165 s | 23 KBi |
#6 |
Tiempo límite excedido
|
1.017 s | 78 KBi |
#7 |
Tiempo límite excedido
|
0.664 s | 59 KBi |
#8 |
Tiempo límite excedido
|
1.1 s | 57 KBi |
#9 |
Tiempo límite excedido
|
1.023 s | 115 KBi |
#10 |
Tiempo límite excedido
|
1.036 s | 76 KBi |
import java.util.Scanner; import java.util.Stack; public class Main { public static int[] processLine(int N, Scanner myObj) { int elements[] = new int[N]; for (int i=0; i < N; i++) { elements[i] = myObj.nextInt(); } return elements; } public static int[] solve(int N, int[] elements) { int[] solution; Stack<Integer> max; solution = new int[N]; max = new Stack<Integer>(); for (int i = N-1; i >= 0; i--) { while (!max.empty() && elements[i] >= max.peek()) { max.pop(); } solution[i] = max.empty() ? -1 : max.peek(); max.push(elements[i]); } return solution; } public static void printCase(int c, int N, int[] solution) { StringBuilder strSol = new StringBuilder("Case #"); strSol.append(c); strSol.append(":"); for (int i=0; i < N; i++) { strSol.append(" "); strSol.append(solution[i]); } System.out.println(strSol); } public static void main(String ...args) { int N, C; int[] elements, solution; Scanner myObj = new Scanner(System.in); C = myObj.nextInt(); for(int i=1; i<=C; i++) { N = myObj.nextInt(); elements = processLine(N, myObj); solution = solve(N, elements); printCase(i, N, solution); } } }