답안 #164604

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
164604 2019-11-22T05:13:13 Z Muhammetali Bootfall (IZhO17_bootfall) C++11
0 / 100
2 ms 504 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a[1001],b[1001],mx,k,yasapbolya,ickimx;
vector<ll>v;
bool f(ll c,ll nacinji)
{
	ickimx=0;
	if (nacinji==n) return true;
	for (ll i=0;i<n;i++) b[i]=a[i];
	b[nacinji]=c;
	for (ll i=0;i<n;i++) ickimx+=b[i];
	sort(b,b+n);
	yasapbolya=0;
	for (ll i=n-1;i>=0;i--)
	{
		if (yasapbolya==ickimx/2) break;
		else if (yasapbolya+b[i]<=ickimx/2) yasapbolya+=b[i];
	}
	if (yasapbolya!=ickimx/2) return false;
	else return f(c,nacinji+1);
}
int main()
{
	cin >> n;
	for (ll i=0;i<n;i++)
	{
		cin >> a[i];
		b[i]=a[i];
		mx+=a[i];
	}
	sort(a,a+n);
	yasapbolya=0;
	for (ll i=n-1;i>=0;i--)
	{
		if (yasapbolya==mx/2) break;
		else if (yasapbolya+a[i]<=mx/2) yasapbolya+=a[i];
	}
	if (yasapbolya!=mx/2)
	{
		cout << 0;
		return 0;
	}
	else
	{
		for (ll i=1;i<=mx;i++)
		{
			for (ll j=0;j<n;j++)
			{
				if (b[j]==i-1 || i==1)
				{
					b[j]=i;
					break;
				}
			}
			sort(b,b+n);
			ickimx=0;
			yasapbolya=0;
			for (ll j=0;j<n;j++) ickimx+=b[j];
			if (ickimx%2==0)
			{
				for (ll j=n-1;j>=0;j--)
				{
					if (yasapbolya==ickimx/2) break;
					else if (yasapbolya+b[j]<=ickimx/2) yasapbolya+=b[j];
				}
				if (yasapbolya==ickimx/2) v.push_back(i);
			}
		}
	}
	for (ll i=0;i<v.size();i++)
	{
		if (f(v[i],0)==false)v[i]=0;
		else k++;
	}
	cout << k << "\n";
	for (ll i=0;i<v.size();i++) if (v[i]!=0) cout << v[i] << " ";
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:71:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (ll i=0;i<v.size();i++)
              ~^~~~~~~~~
bootfall.cpp:77:15: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (ll i=0;i<v.size();i++) if (v[i]!=0) cout << v[i] << " ";
              ~^~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Incorrect 2 ms 376 KB Output isn't correct
3 Halted 0 ms 0 KB -