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

Envío 1386

Problema 0xcf - Mirando al horizonte

  • Autor: judavid.arias
  • Fecha: 2020-10-24 20:40:04 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.171 s 14 KBi
#2
Correcto
0.187 s 14 KBi
#3
Correcto
0.201 s 13 KBi
#4
Correcto
0.149 s 13 KBi
#5
Correcto
0.187 s 13 KBi
#6
Tiempo límite excedido
1.201 s 116 KBi
#7
Tiempo límite excedido
1.05 s 111 KBi
#8
Tiempo límite excedido
1.018 s 85 KBi
#9
Tiempo límite excedido
1.038 s 110 KBi
#10
Tiempo límite excedido
1.111 s 98 KBi
Puntos totales: 50 / 100

Código


import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int c = sc.nextInt();

        for(int j = 0;j<c;j++){
            int N = sc.nextInt();
            int []array = new int[N];
            int []solve= new int[N];
            for(int i = 0;i<N;i++)
            {
                array[i] = sc.nextInt();
            }

            ArrayList<Integer> l = new ArrayList<>();
            for(int i = N-1;i>=0;i--){
                if(l.size() > 0 ){
                    while(!l.isEmpty() && array[i] >= l.get(0)){
                        l.remove(0);
                    }

                    if(l.size() == 0){
                        solve[i] = -1;
                        l.add(0,array[i]);
                    }else{
                        solve[i] = l.get(0);
                        l.add(0,array[i]);
                    }

                }else{
                    solve[i] = -1;
                    l.add(0, array[i]);
                }

            }

            System.out.print("Case #" + (j+1) + ":");
            for(int i = 0;i<N;i++)
                System.out.print(" " + solve[i]);

            System.out.println();

        }
    }
}