Submission #671140

#TimeUsernameProblemLanguageResultExecution timeMemory
671140vuavisaoLabels (NOI20_labels)C++14
100 / 100
50 ms6732 KiB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define ll long long
using namespace std;

template<typename Lhs, typename Rhs> inline void Max_self(Lhs &a, Rhs b) { a = (a > b ? a : b); }
template<typename Lhs, typename Rhs> inline void Min_self(Lhs &a, Rhs b) { a = (a < b ? a : b); }

const ll N = 3e5 + 10;
const ll INF = 1e18;

ll n;
ll a[N];

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    if (fopen("Labels.inp", "r")) {
        freopen("Labels.inp", "r", stdin);
        freopen("Labels.out", "w", stdout);
    }
    cin >> n;
    for(ll i = 2; i <= n; ++ i) {
        cin >> a[i];
        a[i] += a[i - 1];
    }
    ll Min = - INF, Max = INF;
    for(ll i = 2; i <= n; ++ i) {
        if(a[i] == 0) {
            Max_self(Min, 1);
            Min_self(Max, n);
        }
        else if(a[i] < 0) {
            Max_self(Min, abs(a[i]) + 1);
            Min_self(Max, n);
        }
        else {
            Max_self(Min, 1);
            Min_self(Max, n - a[i]);
        }
    }
    if(Min != Max) {
        cout << - 1;
        return 0;
    }
    ll first = Min;
    for(ll i = 1; i <= n; ++ i) cout << first + a[i] << ' ';
    return 0;
}

/// Code by vuavisao

Compilation message (stderr)

Labels.cpp: In function 'int32_t main()':
Labels.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("Labels.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
Labels.cpp:22:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |         freopen("Labels.out", "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...