Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
0.163 s | 13 KBi |
#2 |
Correcto
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
0.173 s | 14 KBi |
#3 |
Correcto
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
0.164 s | 12 KBi |
#4 |
Correcto
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
0.199 s | 13 KBi |
#5 |
Correcto
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
0.164 s | 13 KBi |
#6 |
Tiempo límite excedido
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
1.055 s | 108 KBi |
#7 |
Tiempo límite excedido
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
1.044 s | 118 KBi |
#8 |
Tiempo límite excedido
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
1.028 s | 88 KBi |
#9 |
Tiempo límite excedido
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
0.69 s | 58 KBi |
#10 |
Tiempo límite excedido
Note: Main.java uses or overrides a deprecated API. Note: Recompile with -Xlint:deprecation for details. |
1.057 s | 86 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(new Long(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); } } }