Submission #899245

# Submission time Handle Problem Language Result Execution time Memory
899245 2024-01-05T16:16:39 Z Blagoj Labels (NOI20_labels) C++17
0 / 100
29 ms 6480 KB
#include <bits/stdc++.h>

using namespace std;

#define endl '\n'
#define ll long long
#define all(x) (x).begin(), (x).end()

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    int d[n - 1];
    int add = 1, sum = 1;
    for (int i = 0; i < n - 1; i++) {
        cin >> d[i];
        sum += d[i];
        if (sum < 0) {
            add += abs(sum);
            sum = 0;
        }
        if (sum > n) cout << -1 << endl;
    }
    vector<int> ans(n);
    ans[0] = add;
    for (int i = 0; i < n - 1; i++) ans[i + 1] = ans[i] + d[i];
    for (int i = 0; i < n; i++) {
        if (ans[i] < 0 || ans[i] > n) {
            cout << -1;
            return 0;
        }
    }
    add++;
    vector<int> newAns(n);
    newAns[0] = add;
    for (int i = 0; i < n - 1; i++) newAns[i + 1] = newAns[i] + d[i];
    for (int i = 0; i < n; i++) {
        if (newAns[i] < 0 || newAns[i] > n) {
            for (int i = 0; i < n; i++) cout << ans[i] << " ";
            return 0;
        }
    }
    cout << -1;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 29 ms 6480 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Incorrect 14 ms 4816 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 KB Output is correct
2 Incorrect 0 ms 344 KB Output isn't correct
3 Halted 0 ms 0 KB -