Submission #1288664

#TimeUsernameProblemLanguageResultExecution timeMemory
1288664cubed123Labels (NOI20_labels)C++20
0 / 100
1 ms340 KiB
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define yes cout<<"YES\n"
#define no cout<<"NO\n"
#define endl '\n'
#define pb(x) push_back(x)
 
const int MOD = 1e9+7;
const int inf =1e9;
const ll INF = 1e15;
const ll INV2 = 500000004;

class DSU {
    vector<int> parent, size;
public:
    DSU(int n) {
        parent.resize(n+1);
        size.resize(n+1);
        for (int i=0; i<=n; i++) {
            parent[i]=i;
            size[i]=1;
        }
    }

    int find (int node) {
        if (node==parent[node]) return node;
        return parent[node]=find(parent[node]);
    }

    void unite (int u, int v) {
        int pv=find(v);
        int pu=find(u);

        if (pv==pu) return;
        if (size[pu]<size[pv]) swap(pu, pv);

        parent[pv]=pu;
        size[pu]+=size[pv];
    }

    int getsize (int node) {
        return size[find(node)];
    }
};

ll getsqrt(ll x) {
    ll val = sqrtl(x) + 2;
    while (val * val > x) val--;
    return val;
}

bool safe (int i, int j, int n, int m) {
    if (i<0 || j<0 || i>=n || j>=m) return false;
    return true;
}

ll gcd(ll a, ll b) {
    while (b != 0) {
        ll temp=b;
        b=a%b;
        a=temp;
    }
    return a;
}

ll lcm(ll a, ll b) {
    return a / gcd(a, b)*b;
}

vector<int> dx={-1, 0, 1, 0};
vector<int> dy={0, 1, 0, -1};

// SOLUTION STARTS FROM HERE //

void solve() {
    int n;
    cin>>n;
    
    vector<int> a(n-1);
    for (int i=0; i<n-1; i++) cin>>a[i];

    vector<int> pref(n);
    pref[0]=0;

    for (int i = 1; i < n; ++i) pref[i] = pref[i-1] + a[i-1];

    int mins=pref[0];
    int maxs=pref[0];

    int curs=0;

    for (int i = 1; i < n; ++i) {
        mins = min(mins, pref[i]);
        maxs = max(maxs, pref[i]);
    }

    int l=1-mins;
    int r=n - maxs;

    if (l>r) swap(r, l);

    int cnt=0;
    int val=-1;

    for (int i=l; i<=r; i++) {
        bool pos=true;
        vector<int> seen(n+1, false);


        for (int j=1; j<n-1 && pos; j++) {
            int aj = pref[j]+i;

            if (!(1<=aj && aj<=n)) pos=false;
            if (seen[aj]) pos=false;

            seen[aj]=true;
        }

        if (pos) {
            cnt++;
            val=i;
        }
    }

    if (cnt==1) {
        for (int i=0; i<n; i++) {
            cout<<pref[i]+val<<" ";
        }
    } else {
        cout<<-1<<endl;
    }
}

bool multi=false;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

    //freopen("convention2.in", "r", stdin);
	//freopen("convention2.out", "w", stdout);

    int t=1;
    if (multi) cin>>t;
 
    while (t--) solve();
 
    return 0;
}

Compilation message (stderr)

Labels.cpp: In function 'int main()':
Labels.cpp:144:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  144 |         freopen("input.txt", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
Labels.cpp:145:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  145 |         freopen("output.txt", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...