Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.007 s | 2 KBi |
#2 |
Correcto
|
0.005 s | 7 KBi |
#3 |
Correcto
|
0.006 s | 2 KBi |
#4 |
Correcto
|
0.007 s | 10 KBi |
#5 |
Correcto
|
0.006 s | 1 KBi |
#6 |
Correcto
|
0.223 s | 16 KBi |
#7 |
Correcto
|
0.21 s | 13 KBi |
#8 |
Correcto
|
0.286 s | 12 KBi |
#9 |
Correcto
|
0.198 s | 14 KBi |
#10 |
Correcto
|
0.278 s | 14 KBi |
#include <iostream> #include <vector> #include <algorithm> #include <stack> using namespace std; #define ll long long #define D(x) cout << #x << " " << x << endl vector<ll> solve(vector<ll> &a) { stack<ll> s; vector<ll> ans(a.size()); for(int i = a.size() - 1; i >= 0; --i) { ll curr = a[i]; while(!s.empty()) { ll last = s.top(); if(curr >= last) s.pop(); else { ans[i] = last; break; } } if(s.empty()) ans[i] = -1; s.push(curr); } return ans; } void printAns(vector<ll> ans) { cout << ans[0]; for(int i = 1; i < ans.size(); ++i) cout << " " << ans[i]; cout << endl; } int main() { ll n, t; cin >> t; for(int x = 1; x <= t; ++x) { cin >> n; vector<ll> a(n), ans; for(int i = 0; i < n; ++i) cin >> a[i]; ans = solve(a); cout << "Case #" << x << ": "; printAns(ans); } return 0; }