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

Envío 2343

Problema 0xcf - Mirando al horizonte

  • Autor: Felipe
  • Fecha: 2020-12-14 04:30:43 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Incorrecto
0.131 s 35 KBi
#2
Incorrecto
0.121 s 11 KBi
#3
Incorrecto
0.14 s 15 KBi
#4
Incorrecto
0.144 s 15 KBi
#5
Incorrecto
0.132 s 12 KBi
#6
Incorrecto
0.908 s 63 KBi
#7
Incorrecto
0.958 s 79 KBi
#8
Tiempo límite excedido
1.087 s 93 KBi
#9
Tiempo límite excedido
1.117 s 81 KBi
#10
Tiempo límite excedido
1.145 s 96 KBi
Puntos totales: 0 / 100

Código

import java.io.*;
import java.util.Stack;

public class Main {
	public static void main(String args[]) throws IOException {
		BufferedReader bfr = new BufferedReader(new InputStreamReader(System.in));
		int cases = Integer.parseInt(bfr.readLine());
		for (int c = 1; c <= cases; c++) {
			int n = Integer.parseInt(bfr.readLine());
			
			int buildings[] = new int[n];
			int result[] = new int[n];
			String buildingString[] = bfr.readLine().split(" ");
			Stack<Integer> stack = new Stack<Integer>();

			for (int i = 0; i < n; i++) {
				buildings[i] = Integer.parseInt(buildingString[i]);
			}

			for (int i = n - 1; i >= 0; i--) {
				int building = buildings[i];
				while (!stack.empty() && building >= stack.peek()) {
					stack.pop();
				}
				
				if(!stack.empty() && building < stack.peek()) {
					result[i] = stack.peek();
				}

				if(stack.empty()) {
					result[i] = -1;
				}

				stack.push(building);
			}

			StringBuilder sb = new StringBuilder();
			
			for (int building : result){
				sb.append(building).append(" ");
			}

			System.out.println("Case " + c + ": " + sb.toString());
		}
	}
}