Submission #1314589

#TimeUsernameProblemLanguageResultExecution timeMemory
1314589cubedLabels (NOI20_labels)C++20
0 / 100
1 ms332 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 && !pos; 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) {
            pos=true;
            ans=a;
        }
    }

    bool allequal = true;
    for (int i=1; i<n; i++) {
        if (ans[i]!=ans[i-1]) allequal=false;
    }

    if (allequal && n!=1) pos=false;

    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);
    
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif

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

Compilation message (stderr)

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