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

Envío 2344

Problema 0xcf - Mirando al horizonte

  • Autor: Felipe
  • Fecha: 2020-12-14 04:33:27 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.159 s 16 KBi
#2
Correcto
0.142 s 15 KBi
#3
Correcto
0.155 s 14 KBi
#4
Correcto
0.158 s 28 KBi
#5
Correcto
0.152 s 21 KBi
#6
Tiempo límite excedido
1.054 s 86 KBi
#7
Correcto
0.946 s 78 KBi
#8
Tiempo límite excedido
1.073 s 76 KBi
#9
Correcto
0.958 s 81 KBi
#10
Tiempo límite excedido
1.151 s 75 KBi
Puntos totales: 70 / 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());
		BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(System.out));
		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(" ");
			}

			bfw.write("Case #" + c + ": " + sb.toString() + "\n");
		}
		bfw.flush();
	}
}