Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.007 s | 1 KBi |
#2 |
Correcto
|
0.006 s | 1 KBi |
#3 |
Correcto
|
0.008 s | 1 KBi |
#4 |
Correcto
|
0.006 s | 1 KBi |
#5 |
Correcto
|
0.005 s | 1 KBi |
#6 |
Incorrecto
|
0.253 s | 6 KBi |
#7 |
Correcto
|
0.218 s | 5 KBi |
#8 |
Correcto
|
0.332 s | 9 KBi |
#9 |
Incorrecto
|
0.237 s | 6 KBi |
#10 |
Correcto
|
0.32 s | 8 KBi |
#include<iostream> #include<vector> #include<stack> using namespace std; vector<int> getBlockHeights(vector<int> &h){ stack<pair<int,int>> s; vector<int>sol(h.size(),0); for(int i=0;i<h.size();i++){ if(s.size()==0){ s.push({i,h[i]}); } else{ if(s.size()>0 && s.top().second>=h[i]){ s.push({i,h[i]}); } else{ while(s.size()>0 && s.top().second<=h[i]){ auto sTop = s.top(); if(sTop.second==h[i]){ sol[sTop.first] = -1; } else{ sol[sTop.first] = h[i]; } s.pop(); } s.push({i,h[i]}); } } } while(s.size()>0){ auto sTop = s.top(); sol[sTop.first] = -1; s.pop(); } return sol; } 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; } cout<<"Case #"<<p<<": "; vector<int> sol = getBlockHeights(heights); for(int val: sol){ cout<<val<<" "; } cout<<endl; p++; } return 0; }