This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// In the Name of Allah
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast,unroll-loops,fast-math")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4.1,avx,avx2,sse4.2,popcnt,tune=native")
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back
#define pp pop_back
#define all(x) x.begin(), x.end()
const int N = 1e5 + 12;
int b[N], n, a[N], k;
void ip() {
cin >> n >> k;
for (int i = 0; i < n; i++)
cin >> b[i];
}
void solve() {
bool res = (b[n - 1] == -1);
int c = 0;
for (int i = 0; i < n; i++)
if (b[i] > 1 && b[i + 1] != b[i] - 1)
res = false;
else if (b[i] == -1)
c++;
if (!res) {
cout << -1;
return;
}
for (int i = n - 1; ~i; --i)
if (b[i] == -1)
c--, a[i] = n - c;
int t = 0;
for (int i = 0; i < n; i++)
if (b[i] == 1) {
c++;
a[i] = t + b[i];
t += c;
c = 0;
}
else if (b[i] > 1) {
c++;
a[i] = t + b[i];
}
for (int i = 0; i < n; i++)
cout << a[i] << ' ';
}
int32_t main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
ip(), solve();
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... |