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

Envío 408

Problema 0xcf - Mirando al horizonte

  • Autor: davidtoca
  • Fecha: 2020-09-01 23:00:20 UTC (Hace más de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.006 s 1 KBi
#2
Correcto
0.006 s 6 KBi
#3
Correcto
0.006 s 1 KBi
#4
Correcto
0.006 s 61 KBi
#5
Correcto
0.006 s 1 KBi
#6
Correcto
0.21 s 7 KBi
#7
Correcto
0.174 s 5 KBi
#8
Correcto
0.309 s 15 KBi
#9
Correcto
0.197 s 6 KBi
#10
Correcto
0.256 s 7 KBi
Puntos totales: 100 / 100

Código

#include <iostream>
#include <list>
using namespace std;

int main(){
  int c, n;
  cin >> c;
  for(int i=0; i<c;i++){
    cin >> n;
    int input[n];
    int output[n];

    for(int j=0; j<n; j++){ 
      cin >> input[j];
    }

    list<int> stack;

    for(int j=n-1;j>=0;j--){
      int current = input[j];
      output[j] = -1;
      while(!stack.empty()){

        int taller = stack.front();

        if(current < taller){
          output[j] = taller;
          break;
        } else{
          stack.pop_front();
        }

      }

      stack.push_front(current);

    }

    cout << "Case #" << i+1 << ":";
    for(int j=0; j<n; j++){
        cout << " " << output[j]; 
    }
    cout << endl;

  }
}