Caso # | Resultado | Tiempo | Memoria |
---|---|---|---|
#1 |
Correcto
|
0.005 s | 3 KBi |
#2 |
Correcto
|
0.006 s | 2 KBi |
#3 |
Correcto
|
0.006 s | 2 KBi |
#4 |
Correcto
|
0.005 s | 65 KBi |
#5 |
Correcto
|
0.005 s | 2 KBi |
#6 |
Correcto
|
0.257 s | 8 KBi |
#7 |
Correcto
|
0.199 s | 8 KBi |
#8 |
Correcto
|
0.32 s | 7 KBi |
#9 |
Correcto
|
0.252 s | 8 KBi |
#10 |
Correcto
|
0.286 s | 13 KBi |
#include <iostream> #include <list> #include <vector> using namespace std; vector<int> processLine(int N) { vector<int> elements(N); for (int i=0; i < N; i++) { cin >> elements[i]; } return elements; } vector<int> solve(int N, vector<int> elements) { vector<int> solution(N); list<int> max; for (int i = N-1; i >= 0; i--) { while (!max.empty() && elements[i] >= max.front()) { max.pop_front(); } solution[i] = max.empty() ? -1 : max.front(); max.push_front(elements[i]); } return solution; } void printCase(int c, int N, vector<int> solution) { cout << "Case #" << c << ":"; for (int i=0; i < N; i++) { cout << " " << solution[i]; } cout << endl; } int main() { int N, C; vector<int> elements, solution; cin >> C; for(int i=1; i<=C; i++) { cin >> N; elements = processLine(N); solution = solve(N, elements); printCase(i, N, solution); } }