제출 #673573

#제출 시각아이디문제언어결과실행 시간메모리
673573smartmonkyBootfall (IZhO17_bootfall)C++14
100 / 100
363 ms3520 KiB
#include <bits/stdc++.h>

#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
//#define int long long

using namespace std;

void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
const int N = 501 * 500;
int dp[N];
int used[N];
int main()
{
	int n, sum = 0;
	cin >> n;
	vector <int> v(n);
	for(int i = 0; i < n; i++){
		cin >> v[i];
		sum += v[i];
	}
	if(sum & 1){
		cout << 0;
		return 0;
	}
	dp[0] = 1;
	for(int i = 0; i < n; i++){
		for(int j = sum; j >= v[i]; j--){
			dp[j] += dp[j - v[i]];
		}
	}
	if(!dp[sum / 2]){
		cout << 0;
		return 0;
	}
	vector <int> ans;
	for(int i = 0; i < n; i++){
		int k = sum - v[i];
		for(int j = v[i]; j <= sum; j++){
			dp[j] -= dp[j - v[i]];
		}
		for (int j = 0; j <= k / 2; j++) {
			if (dp[j]) used[k - j * 2]++;
		}
		for(int j = sum ; j >= v[i]; j--){
			dp[j] += dp[j - v[i]];
		}
	}
	for (int i = 0; i <= sum; i++) {
		if (used[i] == n) 
			ans.pb(i);
	}
	cout << ans.size() << endl;
	for(auto x : ans)
		cout << x <<" ";
}

컴파일 시 표준 에러 (stderr) 메시지

bootfall.cpp: In function 'void fp(std::string)':
bootfall.cpp:12:29: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout);}
      |                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:12:70: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | void fp(string name){freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"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...
#Verdict Execution timeMemoryGrader output
Fetching results...