Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.201 s | 14 KBi |
#2 |
Incorrecto
|
0.171 s | 12 KBi |
#3 |
Correcto
|
0.201 s | 13 KBi |
#4 |
Correcto
|
0.2 s | 13 KBi |
#5 |
Incorrecto
|
0.148 s | 12 KBi |
#6 |
Tiempo límite excedido
|
1.145 s | 119 KBi |
#7 |
Tiempo límite excedido
|
1.05 s | 97 KBi |
#8 |
Tiempo límite excedido
|
1.126 s | 101 KBi |
#9 |
Tiempo límite excedido
|
1.017 s | 109 KBi |
#10 |
Tiempo límite excedido
|
1.15 s | 105 KBi |
import java.util.LinkedList; import java.util.Queue; 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(); } Queue<Integer> l = new LinkedList<>(); for(int i = N-1;i>=0;i--){ if(l.size() > 0 ){ while(!l.isEmpty() && array[i] >= l.peek()){ l.poll(); } if(l.size() == 0){ solve[i] = -1; l.offer(array[i]); }else{ solve[i] = l.peek(); l.offer(array[i]); } }else{ solve[i] = -1; l.offer(array[i]); } } System.out.print("Case #" + (j+1) + ":"); for(int i = 0;i<N;i++) System.out.print(" " + solve[i]); System.out.println(); } } }