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

Envío 2764

Problema 0xcf - Mirando al horizonte

  • Autor: pradomaricon
  • Fecha: 2021-02-04 07:19:46 UTC (Hace alrededor de 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.008 s 2 KBi
#2
Correcto
0.004 s 1 KBi
#3
Correcto
0.008 s 1 KBi
#4
Correcto
0.007 s 2 KBi
#5
Correcto
0.008 s 1 KBi
#6
Correcto
0.334 s 6 KBi
#7
Correcto
0.19 s 7 KBi
#8
Correcto
0.33 s 7 KBi
#9
Correcto
0.331 s 7 KBi
#10
Correcto
0.229 s 7 KBi
Puntos totales: 100 / 100

Código

#include <iostream>
#include <vector>
#include <stack>


using namespace std;
void  horizontes(int length,vector<int> a,vector<int> &soluc);
int main(){
    int numCases;
    cin >> numCases;
   
    
    for(int i=0;i<numCases;++i){
        int length;
        cin >> length;
        vector<int> a(length);
        vector<int> soluciones(length);
        for(int j=0;j<length;j++){
            cin >> a[j];
        }
        horizontes(length,a,soluciones);
        
        //printar formatteado
        cout << "Case #"<< i + 1 << ": ";
        for(int j=0;j<length;j++){
            cout << soluciones[j] << " ";
        }
        cout << "\n";

    }
    
    
}

void horizontes(int length,vector<int> a, vector<int> &soluciones){
    stack<int> blockers;
    
    for(int k=length-1;k>-1;k--){
        while(!blockers.empty() && a[k]>=blockers.top()){
            blockers.pop();
        }
        if (blockers.empty()){
            soluciones[k]=-1;
        }else{
            soluciones[k]= blockers.top();
        }
        blockers.push(a[k]);
    }
    
    
    
    
//    for(int k =0;k<length;k++){
//        bool blocked = false;
//        int j = k+1;
//        while(!blocked && j<length+1){
//            if(a[j]>a[k]){
//                blocked = true;
//                soluc[k]=a[j];
//            }
//            j++;
//        }
//        if(j==length+1){
//            soluc[k]=-1;
//        }
//    }
    

}