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

Envío 6347

Problema 0xcf - Mirando al horizonte

  • Autor: rpedrazacoello
  • Fecha: 2022-06-19 20:16:13 UTC (Hace casi 2 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.105 s 14 KBi
#2
Correcto
0.12 s 17 KBi
#3
Correcto
0.136 s 17 KBi
#4
Correcto
0.123 s 16 KBi
#5
Correcto
0.127 s 13 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.456 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.494 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.748 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.623 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.719 s 125 KBi
Puntos totales: 50 / 100

Código

import java.util.AbstractMap;
import java.util.Map;
import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int c = scanner.nextInt();
        for(int i=0; i<c; i++){
            int n = scanner.nextInt();
            int[] buildings = new int[n];
            int[] buildingsResults = new int[n];

            for(int j=0; j<buildings.length; j++){
                buildings[j]=scanner.nextInt();
                buildingsResults[j] = -1;
            }

            Stack<Map.Entry<Integer, Integer>> stack = new Stack<>();

            for(int j=0; j<buildings.length; j++){
                Map.Entry<Integer, Integer> value = new AbstractMap.SimpleEntry<>(j, buildings[j]);

                while (!stack.isEmpty() && stack.peek().getValue() < buildings[j]){
                    Map.Entry<Integer, Integer> stackedValue = stack.pop();
                    buildingsResults[stackedValue.getKey()] = buildings[j];
                }

                stack.add(value);
            }

            System.out.print("Case #" +(i+1) +": ");
            for(int j=0; j<buildingsResults.length; j++){
                if(j == buildings.length-1){
                    System.out.print(buildingsResults[j]);
                } else {
                    System.out.print(buildingsResults[j] + " ");
                }
            }
            System.out.println();
        }
    }
}