█████████ ████ ███░░░░░███ ░░███ ███ ░░░ ██████ ███████ ██████ ██████ ░███ ███░░███ ███░░███ ███░░███ ███░░███ ░███ ░███ ░███░███ ░███ ░███████ ░███ ░███ ░░███ ███░███ ░███░███ ░███ ░███░░░ ░███ ░███ ░░█████████ ░░██████ ░░████████░░██████ ░░██████ ░░░░░░░░░ ░░░░░░ ░░░░░░░░ ░░░░░░ ░░░░░░

Envío 4406

Problema 0xcf - Mirando al horizonte

  • Autor: 8cypherp
  • Fecha: 2021-06-16 21:34:59 UTC (Hace casi 3 años)
Caso # Resultado Tiempo Memoria
#1
Correcto
0.004 s 18 KBi
#2
Correcto
0.004 s 1 KBi
#3
Correcto
0.006 s 28 KBi
#4
Correcto
0.004 s 8 KBi
#5
Error interno
No such file or directory @ rb_sysopen - /box/main.cpp
#6
Correcto
0.16 s 6 KBi
#7
Correcto
0.126 s 6 KBi
#8
Correcto
0.242 s 5 KBi
#9
Correcto
0.222 s 12 KBi
#10
Correcto
0.221 s 7 KBi
Puntos totales: 90 / 100

Código

#include <iostream>
#include <vector>
#include <list>
using namespace std;

void solve() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }

  vector<int> next(n);
  for (int i = n - 1; i >= 0; --i) {
    next[i] = i + 1;
    while (next[i] < n and a[i] >= a[next[i]]) {
      next[i] = next[next[i]];
    }
  }
  for (int i = 0; i < n; ++i) {
    if (next[i] >= n) {
      cout << " -1";
    } else {
      cout << " " << a[next[i]];
    }
  }
  cout << endl;
}

int main() {
  int cases;
  cin >> cases;
  for (int c = 1; c <= cases; ++c) {
    cout << "Case #" << c << ":";
    solve();
  }
  return 0;
}