Submission #1016290

#TimeUsernameProblemLanguageResultExecution timeMemory
1016290toast12Labels (NOI20_labels)C++14
100 / 100
86 ms7968 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> nums(n); for (int i = 1; i < n; i++) { cin >> nums[i]; } vector<int> ps(n); for (int i = 1; i < n; i++) { ps[i] = ps[i-1]+nums[i]; } auto it = max_element(ps.begin(), ps.end()); int x = *min_element(ps.begin(), ps.end()); if (*it-x != n-1) { cout << "-1\n"; return 0; } vector<int> ans(n); int idx = it-ps.begin(); ans[idx] = n; for (int i = idx+1; i < n; i++) { ans[i] = ans[i-1]+nums[i]; } for (int i = idx-1; i >= 0; i--) { ans[i] = ans[i+1]-nums[i+1]; } for (int i = 0; i < n; i++) { cout << ans[i] << ' '; } cout << '\n'; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...