Submission #1300097

#TimeUsernameProblemLanguageResultExecution timeMemory
1300097khoianhLabels (NOI20_labels)C++20
25 / 100
28 ms9476 KiB
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int mn = 3e5 + 5; ll n, a[mn], b[mn], f[mn]; pair<ll, ll> l, r; void solve(){ cin >> n; for(int i = 1; i <= n; ++i) f[i] = 0; for(int i = 2; i <= n; ++i) cin >> b[i]; l.second = r.second = 1; l.first = r.first = 0; ll cur = 0; for(int i = 2; i <= n; ++i){ cur += b[i]; l = max(l, {cur, i}); r = min(r, {cur, i}); } a[l.second] = n; a[r.second] = 1; if(l.second < r.second){ for(int i = l.second - 1; i >= 1; --i) a[i] = a[i + 1] - b[i + 1]; for(int i = r.second - 1; i > l.second; --i) a[i] = a[i + 1] - b[i + 1]; for(int i = r.second + 1; i <= n; ++i) a[i] = b[i] + a[i - 1]; } else { for(int i = r.second - 1; i >= 1; --i) a[i] = a[i + 1] - b[i + 1]; for(int i = l.second - 1; i > r.second; --i) a[i] = a[i + 1] - b[i + 1]; for(int i = l.second + 1; i <= n; ++i) a[i] = b[i] + a[i - 1]; } for(int i = 1; i <= n; ++i){ if(a[i] < 1 || a[i] > n){ cout << -1; return; } } for(int i = 2; i <= n; ++i){ if(a[i] - a[i - 1] != b[i]){ cout << -1; return; } } for(int i = 1; i <= n; ++i){ if(f[a[i]]){ cout << -1; return; } f[a[i]] = 1; } for(int i = 1; i <= n; ++i) cout << a[i] << " "; return; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); if(fopen(".INP", "r")) { freopen(".INP", "r", stdin); freopen(".OUT", "w", stdout); } int testCase = 1; //cin >> testCase; while(testCase--) solve(); }

Compilation message (stderr)

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