This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <iomanip>
#include <vector>
#include <bitset>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>
#define endl '\n'
#define X first
#define Y second
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int maxn = 1e5+10;
int brr[maxn];
int ans[maxn];
int bef[maxn];
int aft[maxn];
inline void die()
{
cout << -1 << endl;
exit(0);
}
inline void join(int x)
{
int b = bef[x];
int a = aft[x];
bef[a] = b;
aft[b] = a;
}
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, k; cin >> n >> k; // k == 1
set<int> rems;
aft[0] = 1;
int c = 0;
for(int i = 1; i <= n; i++)
{
cin >> brr[i];
c += (brr[i] != -1);
if(brr[i] == 1)
rems.insert(i);
bef[i] = i-1;
aft[i] = i+1;
}
int d = n;
for(int i = 1; i <= n; i++)
{
if(brr[i] != -1) continue;
ans[i] = d--;
join(i);
}
bef[n+1] = n;
for(int i = 1; i <= c; i++)
{
if(rems.empty())
die();
int x = *rems.begin();
rems.erase(rems.begin());
ans[x] = i;
if(brr[bef[x]] == brr[x]+1)
rems.insert(bef[x]);
join(x);
}
for(int i = 1; i <= n; i++)
cout << ans[i] << " ";
cout << endl;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |