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

Envío 2542

Problema 0xcf - Mirando al horizonte

Caso # Resultado Tiempo Memoria
#1
Correcto
0.006 s 2 KBi
#2
Incorrecto
0.006 s 32 KBi
#3
Correcto
0.007 s 32 KBi
#4
Correcto
0.006 s 2 KBi
#5
Incorrecto
0.007 s 28 KBi
#6
Incorrecto
0.175 s 7 KBi
#7
Correcto
0.228 s 8 KBi
#8
Correcto
0.275 s 6 KBi
#9
Incorrecto
0.15 s 6 KBi
#10
Incorrecto
0.225 s 8 KBi
Puntos totales: 50 / 100

Código

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

using namespace std;

int main(){
    int c;
    cin>>c;
    int p = 1;
    while(c--){
        int n;
        cin>>n;
        vector<int> heights(n,0);
        for(auto &h: heights){
            cin>>h;
        }
        vector<int> sol(n,0);
        sol[n-1] = heights[n-1];
        int currentMax = heights[n-1];
        for(int i=n-1;i>=0;i--){
            if(currentMax==heights[i]){
                sol[i] = -1;
            }
            else if(currentMax<heights[i]){
                currentMax = heights[i];
                sol[i]=-1;
            }
            else{
                sol[i] = currentMax;
            }
        }
        cout<<"Case #"<<p<<": ";
        for(auto &val:sol){
            cout<<val<<" ";
        }
        cout<<endl;
        p++;
    }
    return 0;
}