# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
320462 | egas | Labels (NOI20_labels) | C++14 | 271 ms | 29016 KiB |
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 <bits/stdc++.h>
using namespace std;
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
vector<long long> a(n-1);
for(long long i = 0 ; i < n-1 ; i++) {
cin >> a[i];
}
vector<long long> pref;
pref.push_back(a[0]);
for(long long i=1; i<n-1; i++) {
pref.push_back(pref.back()+a[i]);
}
long long maxi = *max_element(pref.begin(),pref.end());
long long mini = *max_element(pref.begin(),pref.end());
long long xo=min(n,n-maxi);
bool hoga=true;
if(maxi+xo<1 or maxi+xo>n or mini+xo<1 or mini+xo>n)
hoga=false;
vector<long long> res;
res.push_back(xo);
map<long long,long long> freq;
freq[xo]=1;
for(long long i=0; i<n-1; i++) {
res.push_back(res.back()+a[i]);
freq[res.back()]++;
}
if(freq[1]==0 or freq[n]==0)hoga=false;
for(long long i = 0 ; i < res.size() ; i++) {
if(res[i]<1 or res[i]>n)hoga=false;
}
if(hoga) {
for(auto t : res )cout<<t<<" ";
cout << '\n';
} else {
cout << -1 << '\n';
}
return 0;
}
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... |