Submission #1300094

#TimeUsernameProblemLanguageResultExecution timeMemory
1300094khoianhLabels (NOI20_labels)C++20
7 / 100
8 ms2624 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mn = 1e5 + 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 = 1;
	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 = 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:52:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   52 |                 freopen(".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Labels.cpp:53:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   53 |                 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...