답안 #383323

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
383323 2021-03-29T15:37:27 Z MODDI Labels (NOI20_labels) C++14
0 / 100
96 ms 4828 KB
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define mp make_pair
#define pb push_back
using namespace std;
int n;
vi d, pref;
bool check(int mid){
	for(int i = 0; i < pref.size(); i++){
		if(pref[i] + mid <= n && pref[i] + mid > 0)
			continue;
		else{
			return false;
		}
	}
	return true;
}
int main(){
	
	cin>>n;
	for(int i = 0; i < n-1; i++){
		int a;
		cin>>a;
		d.pb(a);
	}
	pref.pb(d[0]);
	for(int i = 1; i < n - 1; i++)
		pref.pb(d[i] + pref[i-1]);
	int l = 1, r = n, mid, smallest_working = 1e9, biggest_working = 0;
	while(l <= r){
		mid = (l + r) / 2;
		//cout<<mid<<endl;
		bool works = check(mid);
		if(works){
			smallest_working = min(smallest_working, mid);
			biggest_working = max(biggest_working, mid);
			//cout<<mid<<endl;
			l = mid + 1;
		}
		else
			r = mid - 1;
	}
	//cout<<smallest_working<<" "<<biggest_working<<endl;
	if(smallest_working != biggest_working)
		cout<<-1<<endl;
	else{
		for(int i = 0; i < n; i++)
		{
			if(i == 0)
				cout<<smallest_working<<" ";
			else
				cout<<pref[i-1] + smallest_working<<" ";
		}
	}
	return 0;
}

Compilation message

Labels.cpp: In function 'bool check(int)':
Labels.cpp:13:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   13 |  for(int i = 0; i < pref.size(); i++){
      |                 ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 96 ms 4828 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Incorrect 69 ms 4572 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 384 KB Output is correct
2 Incorrect 1 ms 364 KB Output isn't correct
3 Halted 0 ms 0 KB -