Cod sursa(job #2750728)

Utilizator cyg_dawidDavid Ghiberdic cyg_dawid Data 12 mai 2021 23:20:52
Problema Schi Scor 55
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.02 kb
#include <fstream>

std::ifstream fin ("schi.in");
std::ofstream fout ("schi.out");

int const nmax = 30000;

struct MyStruct {
    int val;
    int fol; // following
} v[nmax + 5];

int main() {
    int n;
    fin >> n;
    int used = 0;
    v[0].val = -1;
    v[0].fol = -1;
    for (int i = 1; i <= n; i++) {
        bool checked = false;
        int new_pos;
        fin >> new_pos;
        int ind = 0, cnt = 0;
        while (v[ind].fol != -1) {
            if (cnt + 1 == new_pos) {
                int afterind = v[ind].fol;
                v[ind].fol = ++used;
                v[used].val = i;
                v[used].fol = afterind;
                checked = true;
                break;
            }
            ind = v[ind].fol;
            cnt++;
        }
        if (!checked) {
            v[ind].fol = ++used;
            v[used].val = i;
            v[used].fol = -1;
        }
    }
    int ind = 0;
    while (ind != -1) {
        if (ind)
            fout << v[ind].val << "\n";
        ind = v[ind].fol;
    }
    return 0;
}