답안 #337937

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
337937 2020-12-22T06:42:59 Z kutbilim_one Bootfall (IZhO17_bootfall) C++14
0 / 100
1 ms 364 KB
/** kutbilim.one **/
#include <bits/stdc++.h>

using namespace std;

#define all(x) x.begin(),x.end()
//#define int long long
#define endl '\n'
                                /*
ifstream in("test.txt"); 
#define cin in                    */

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

	int n; cin >> n;
	int a[n];
	int sum = 0;
	for(int i = 0; i < n; i++) 
		cin >> a[i], sum += a[i];

	sort(a, a+n);
	             
	int MAX = sum;
	int dp[MAX+1];
	short used[MAX+1]; 
	dp[0] = 1;
	for(int k = 0; k < n; k++){
  	 	for(int x = MAX-a[k]; x >= 0; x--){
   			dp[x+a[k]] += dp[x];
    	} 
    }

    if(sum%2 == 1 || dp[sum/2] == 0) return cout << 0, 0;

    for(int ex = 0; ex < n; ex++){
    	int left = sum-a[ex];
    	for(int x = 0; x <= left; x++)
    		dp[x + a[ex]] -= dp[x];
    
       	for(int right = 0; right <= MAX; right++)
    		if((left+right)%2 == 1 || dp[(left+right)/2] == 0) used[right] = 1;
   	
   		for(int x = left; x >= 0; x--)
   			dp[x + a[ex]] += dp[x]; 	
    }

    vector<int> res;
    for(int i = 0; i <= MAX; i++){
    	if(!used[i]) res.push_back(i);	
    } 

    cout << res.size() << endl;
    for(auto i : res) cout << i << " ";

    return 0;
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:42:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   42 |         for(int right = 0; right <= MAX; right++)
      |         ^~~
bootfall.cpp:45:6: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   45 |      for(int x = left; x >= 0; x--)
      |      ^~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 364 KB Output isn't correct
2 Halted 0 ms 0 KB -