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.185 s | 13 KBi |
#6 |
Tiempo límite excedido
|
0.791 s | 62 KBi |
#7 |
Tiempo límite excedido
|
1.051 s | 125 KBi |
#8 |
Tiempo límite excedido
|
0.449 s | 41 KBi |
#9 |
Tiempo límite excedido
|
1.079 s | 125 KBi |
#10 |
Tiempo límite excedido
|
1.085 s | 110 KBi |
import java.util.Scanner; import java.util.Stack; public class Main { public static long[] processLine(int N, Scanner myObj) { long elements[] = new long[N]; for (int i=0; i < N; i++) { elements[i] = myObj.nextLong(); } return elements; } public static long[] solve(int N, long[] elements) { long[] solution; Stack<Long> max; solution = new long[N]; max = new Stack<Long>(); 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, long[] 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; long[] 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); } } }