Submission #1249304

#TimeUsernameProblemLanguageResultExecution timeMemory
1249304M_SH_OLabels (NOI20_labels)C++20
100 / 100
32 ms6984 KiB
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <set>
#include <queue>
#include <map>
#include <stack>
#include <bitset>
#include <string>
#include <cstring>
#include <iterator>
#include <random>
#define ll long long
#define ll1 long long
#define ull unsigned long long
#define dou long double
#define str string
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll, ll>
#define vpll vector<pll>
#define vbool vector<bool>
#define vstr vector<str>
#define vvll vector<vll>
#define pb push_back
#define pf push_front
#define endl "\n"
#define fr first
#define se second
// #define sortcmp(a) sort(a.begin(), a.end(), cmp)
#define sort(a) sort(a.begin(), a.end())
#define reverse(a) reverse(a.begin(), a.end())
#define speed ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define INF 1000000000000000000
#define ordered_set tree<ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;
//using namespace __gnu_pbds;

mt19937 rng(time(0));
ll randll(ll l, ll r){
    return uniform_int_distribution<ll>(l, r)(rng);
}

int main(){
    speed;

    ll n;
    cin >> n;
    vll a(n);
    ll p = 0, x = -1, x1 = -1;
    ll maxl = 0, minl = 0;
    bool q = 0;
    for(int i =0 ; i < n-1; i ++){
        cin >> a[i];
        p += a[i];
        maxl = max(maxl, p);
        minl = min(minl, p);
        if(maxl-minl == n-1 && !q){
            q = 1;
            if(p >= 0) x = i+1;
            else x1 = i+1;
        }
    }
    
    if(x == -1 && x1 == -1){
        cout << -1 << endl;
        return 0;
    }
    vll b(n);
    if(x != -1){
        b[x] = n;
        for(int i = x+1; i < n; i ++){
            b[i] = b[i-1]+a[i-1];
        }
        for(int i = x-1; i >= 0; i --){
            b[i] = b[i+1]-a[i];
        }
            
    }
    else{
        
        b[x1] = 1;
        for(int i = x1+1; i < n; i ++){
            b[i] = b[i-1]+a[i-1];
        }
        for(int i = x1-1; i >= 0; i --){
            b[i] = b[i+1]-a[i];
        }
    }
    
    for(int i = 0; i < n; i ++){
        cout << b[i] << ' ';
    }
    cout << endl;
    
}
















#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...