| # | Time | Username | Problem | Language | Result | Execution time | Memory |
|---|---|---|---|---|---|---|---|
| 1300095 | khoianh | Labels (NOI20_labels) | C++20 | 27 ms | 9252 KiB |
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn = 3e5 + 5;
ll n, a[mn], b[mn], f[mn];
pair<ll, ll> l, r;
void solve(){
cin >> n;
for(int i = 1; i <= n; ++i) f[i] = 0;
for(int i = 2; i <= n; ++i) cin >> b[i];
l.second = r.second = 1;
l.first = r.first = 0;
ll cur = 0;
for(int i = 2; i <= n; ++i){
cur += b[i];
l = max(l, {cur, i});
r = min(r, {cur, i});
}
a[l.second] = n;
a[r.second] = 1;
if(l.second < r.second){
for(int i = l.second - 1; i >= 1; --i) a[i] = a[i + 1] - b[i + 1];
for(int i = r.second - 1; i > l.second; --i) a[i] = a[i + 1] - b[i + 1];
for(int i = r.second + 1; i <= n; ++i) a[i] = b[i] + a[i - 1];
} else {
for(int i = r.second - 1; i >= 1; --i) a[i] = a[i + 1] - b[i + 1];
for(int i = l.second - 1; i > r.second; --i) a[i] = a[i + 1] - b[i + 1];
for(int i = l.second + 1; i <= n; ++i) a[i] = b[i] + a[i - 1];
}
for(int i = 2; i <= n; ++i){
if(a[i] - a[i - 1] != b[i]){
cout << -1;
return;
}
}
for(int i = 1; i <= n; ++i){
if(f[a[i]]){
cout << -1;
return;
}
f[a[i]] = 1;
}
for(int i = 1; i <= n; ++i) cout << a[i] << " ";
return;
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
if(fopen(".INP", "r")) {
freopen(".INP", "r", stdin);
freopen(".OUT", "w", stdout);
}
int testCase = 1;
//cin >> testCase;
while(testCase--) solve();
}
Compilation message (stderr)
| # | 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... | ||||
