이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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... |