Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.007 s | 2 KBi |
#2 |
Correcto
|
0.006 s | 4 KBi |
#3 |
Correcto
|
0.007 s | 3 KBi |
#4 |
Correcto
|
0.007 s | 1 KBi |
#5 |
Correcto
|
0.008 s | 1 KBi |
#6 |
Correcto
|
0.304 s | 7 KBi |
#7 |
Correcto
|
0.27 s | 6 KBi |
#8 |
Correcto
|
0.334 s | 18 KBi |
#9 |
Correcto
|
0.256 s | 7 KBi |
#10 |
Correcto
|
0.29 s | 7 KBi |
#include<bits/stdc++.h> using namespace std; #define optimizar_io ios_base::sync_with_stdio(0); cin.tie(0); int main() { int cases, n, tam, ii=1; cin >> cases; while(cases--){ cin >> tam; vector<int> numbers; while(tam--){ cin >> n; numbers.push_back(n); } stack<int> aux; int answer[numbers.size()]; for(int i=numbers.size()-1;i>=0;i--){ while(aux.size()>0 and numbers[i] >= aux.top()) aux.pop(); if(aux.size() == 0) answer[i] = -1; else answer[i] = aux.top(); aux.push(numbers[i]); } cout << "Case #" << (ii++) << ": "; for(int i=0;i<numbers.size();i++){ if(i+1 == numbers.size()) cout << answer[i] << endl; else cout << answer[i] << " "; } } return 0; }