Submission #1314591

#TimeUsernameProblemLanguageResultExecution timeMemory
1314591cubedLabels (NOI20_labels)C++20
47 / 100
1095 ms7380 KiB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define f first
// #define s second
#define pb(x) push_back(x)
#define int long long
 
const int MOD = 1e9+7;
const int inf = 1e9;
const int INF = 1e18+20;
const int LOG = 25;

int mex(vector<int>& a) {
    int n =a.size();
    vector<int> seen(n+20, 0);

    for (int x : a) {
        if (0<=x && x<=n)
            seen[x]=1;
    }

    for (int i=0; i<=n; i++) {
        if (!seen[i])
            return i;
    }
    return n;
}

void solve() {
    int n;
    cin>>n;

    vector<int> d(n-1);
    for (int i=0; i<n-1; i++) {
        cin>>d[i];
    }

    vector<int> ans;
    bool pos = false;

    for (int i=1; i<=n; i++) {
        // let i be the arbitray a[0]
        vector<int> a(n);
        a[0]=i;

        for (int j=1; j<n; j++) {
            a[j] = a[j-1]+d[j-1];
        }

        bool tt=true;
        for (auto x:a) {
            if (x<=0 || x>n) {
                tt=false;
                break;
            }
        }

        if (tt) {
            if (pos) {
                pos=false;
                break;
            }

            pos=true;
            ans=a;
        }
    }

    if (!pos) {
        cout<<-1<<endl;
    } else {
        for (auto x:ans) cout<<x<<" ";
    }
}

bool multi=false;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t=1;
    if (multi) cin>>t;
 
    while (t--) solve();
 
    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...