Submission #1300114

#TimeUsernameProblemLanguageResultExecution timeMemory
1300114BuiDucManh123Labels (NOI20_labels)C++20
100 / 100
34 ms4748 KiB
#include <bits/stdc++.h>
#define TN ""
using namespace std;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int a[300009], d[300009];
void Solve(){
    int n;
    cin >> n;
    int mi = 0;
    int sum = 0;
    for(int i = 1; i < n; i++){
        cin >> d[i];
        sum += d[i];
        mi = min(mi, sum);
    }
    a[1] = -mi + 1;
    bool check = false;
    if(a[1] > n){
        cout << -1;
        return;
    }
    for(int i = 1; i < n; i++){
        a[i + 1] = a[i] + d[i];
        if(a[i + 1] > n){
            cout << -1;
            return;
        }
    }
    for(int i = 1; i <= n; i++){
        if(a[i] == n){
            check = true;
        }
    }
    if(!check){
        cout << -1;
        return;
    }
    for(int i = 1; i <= n; i++){
        cout << a[i] << " ";
    }
}
signed main() {
    if(fopen(TN".inp", "r")){
        freopen(TN".inp", "r", stdin);
        freopen(TN".out", "w", stdout);
    }
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test = 1;
    //cin >> test;
    while(test--){
        Solve();
    }
    return 0;
}



Compilation message (stderr)

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