9672022-02-06 13:13:16nmarciTitkos sorozatcpp11Elfogadva 40/4082ms17352 KiB
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <list>
#include <ctime>

using namespace std;
using ll = long long int;

ll inf = 1e9+7;

void test(vector<int>& v, vector<int>& ans){
    int n = v.size();
    int ctr = n;
    vector<vector<int>> g(n);
    ans.resize(n,0);
    for(int i = 0; i < n; ++i){
        if(v[i] == -1){
            ans[i] = ctr--;
        }
        else{
            g[v[i] - 1].push_back(i);
        }
    }
    int i = n - 1;
    while(i >= 0){
        for(auto j : g[i]){
            ans[j] = ctr--;
        }
        --i;
    }
}

vector<int> kodol(vector<int>& v){
    vector<int> ret;
    for(int i = 0; i < v.size(); ++i){
        int ptr = i + 1;
        while(ptr < v.size() && v[ptr] < v[i]) ++ptr;
        if(ptr == v.size()) ret.push_back(-1);
        else ret.push_back(ptr + 1);
    }
    return ret;
}

int main(){
    int n;
    cin >> n;
    vector<int> v(n);
    vector<int> ans(n);
    for(auto& i : v){
        cin >> i;
    }
    test(v,ans);
    for(auto i : ans)
        cout << i << " ";
    cout << endl;
    /*int n;
    cin >> n;
    vector<int> v(n);
    for(int i = 0; i < n; ++i){
        v[i] = i + 1;
    }
    while(next_permutation(v.begin(), v.end())){
        vector<int> kod = kodol(v);
        vector<int> dekodolt(n);
        test(kod, dekodolt);
        vector<int> chk = kodol(dekodolt);
        if(chk != kod){
            cerr << "v:" << endl;
            for(auto i : v)
                cerr << i << " ";
            cerr << endl;
            cerr << "kod:" << endl;
            for(auto i : kod)
                cerr << i << " ";
            cerr << endl;
            cerr << "dek:" << endl;
            for(auto i : dekodolt)
                cerr << i << " ";
            cerr << endl;
        }
    }*/
    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/02ms1736 KiB
2Elfogadva0/025ms6648 KiB
3Elfogadva1/11ms2112 KiB
4Elfogadva1/11ms2116 KiB
5Elfogadva2/21ms2128 KiB
6Elfogadva1/12ms2168 KiB
7Elfogadva1/11ms2168 KiB
8Elfogadva2/22ms2172 KiB
9Elfogadva2/257ms11952 KiB
10Elfogadva2/259ms12544 KiB
11Elfogadva2/254ms13108 KiB
12Elfogadva2/250ms13680 KiB
13Elfogadva2/250ms14260 KiB
14Elfogadva2/282ms14968 KiB
15Elfogadva2/254ms15808 KiB
16Elfogadva3/352ms16132 KiB
17Elfogadva3/352ms16164 KiB
18Elfogadva3/352ms16192 KiB
19Elfogadva3/350ms16308 KiB
20Elfogadva3/352ms17352 KiB
21Elfogadva1/150ms15280 KiB
22Elfogadva1/148ms15140 KiB
23Elfogadva1/146ms15124 KiB