Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.008 s | 2 KBi |
#2 |
Correcto
|
0.006 s | 1 KBi |
#3 |
Correcto
|
0.02 s | 2 KBi |
#4 |
Correcto
|
0.007 s | 1 KBi |
#5 |
Correcto
|
0.005 s | 11 KBi |
#6 |
Correcto
|
0.158 s | 5 KBi |
#7 |
Correcto
|
0.14 s | 5 KBi |
#8 |
Correcto
|
0.306 s | 7 KBi |
#9 |
Correcto
|
0.217 s | 19 KBi |
#10 |
Correcto
|
0.173 s | 7 KBi |
#include<bits/stdc++.h> using namespace std; #define el "\n" int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int T; cin>>T; for(int i = 0; i < T; ++i){ int n; cin>>n; vector<int>v; vector<int>ans; stack<int>s; v.push_back(0); for(int j = 1; j <= n; ++j){ int m; cin>>m; v.push_back(m); } s.push(v[n]); ans.push_back(-1); for(int j = n - 1; j >= 0; --j){ if(s.top() > v[j]){ ans.push_back(s.top()); s.push(v[j]); }else{ while(s.size() > 0){ if(s.top() <= v[j] && s.size() == 1){ ans.push_back(-1); s.pop(); s.push(v[j]); break; }else if( s.top() > v[j]){ ans.push_back(s.top()); s.push(v[j]); break; }else{ s.pop(); } } } } cout<<"Case #"<<i + 1<<":"<<" "; for(int j = n-1 ; j >= 0; --j){ cout<<ans[j]<<" "; } cout<<el; ans.clear(); v.clear(); } return 0; }