Submission #1181726

#TimeUsernameProblemLanguageResultExecution timeMemory
1181726ThunnusLabels (NOI20_labels)C++20
100 / 100
35 ms11844 KiB
#include<bits/stdc++.h> using namespace std; using i64 = long long; #define int i64 #define vi vector<int> #define vvi vector<vi> #define vb vector<bool> #define pii pair<int, int> #define fi first #define se second #define sz(x) (int)(x).size() inline void solve(){ int n; cin >> n; vi d(n - 1); for(int &i : d){ cin >> i; } int sm = 0, mnn = 0, mxx = 0z; vi mn(n - 1, 0), mx(n - 1, 0); for(int i = 0; i < n - 1; i++){ sm += d[i]; mnn = min(mnn, sm); mxx = max(mxx, sm); mn[i] = mnn; mx[i] = mxx; } int frst = -1; for(int i = 0; i < n - 1; i++){ if(mx[i] - mn[i] == n - 1){ if(frst != -1 && frst != n - mx[i]){ cout << "-1\n"; return; } frst = n - mx[i]; } } vi a(n); a.front() = frst; for(int i = 0; i < n - 1; i++){ a[i + 1] = a[i] + d[i]; } for(int i = 0; i < n; i++){ if(a[i] > n || a[i] <= 0){ cout << "-1\n"; return; } } for(int &i : a){ cout << i << " "; } cout << "\n"; return; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; //cin >> t; while(t--){ solve(); } return 0; }

Compilation message (stderr)

Labels.cpp:21:32: warning: use of C++23 'make_signed_t<size_t>' integer constant
   21 |     int sm = 0, mnn = 0, mxx = 0z;
      |                                ^~
#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...