█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 424

Problema 0xcf - Mirando al horizonte

  • Autor: edwaraco
  • Fecha: 2020-09-03 17:24:13 UTC (Hace más de 4 años)
Caso # Resultado Tiempo Memoria
#1
Error de compilación
                      Compilation time limit exceeded.
                    
#2
Error de compilación
                      Compilation time limit exceeded.
                    
#3
Correcto
                      Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

                    
0.236 s 49 KBi
#4
Error de compilación
                      Compilation time limit exceeded.
                    
#5
Error de compilación
                      Compilation time limit exceeded.
                    
#6
Tiempo límite excedido
                      Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

                    
0.967 s 115 KBi
#7
Tiempo límite excedido
                      Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

                    
1.055 s 93 KBi
#8
Tiempo límite excedido
                      Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

                    
1.032 s 78 KBi
#9
Tiempo límite excedido
                      Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

                    
0.893 s 61 KBi
#10
Tiempo límite excedido
                      Note: Main.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

                    
1.048 s 93 KBi
Puntos totales: 10 / 100

Código

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 i, long[] solution) {
        System.out.print("Case #" + i + ":");
        for (long e: solution) {
            System.out.print(" " + e);
        }
        System.out.println("");
    }

    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, solution);
        }    
    }
}