답안 #343382

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
343382 2021-01-03T20:08:15 Z Kalashnikov Bootfall (IZhO17_bootfall) C++17
0 / 100
1 ms 492 KB
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
 
using namespace std;
using ll = long long;
 
const int N = 500+5 , inf = 2e9 + 7;
const ll INF = 1e18 ,   mod = 1e9+7 , P = 6547;

int a[N];
int ord[500*260];

bitset<500*260> dp[N];


void solve() {
	int n;
	cin >> n;
	int sum = 0;
	for(int i = 1; i <= n; i ++) {
		cin >> a[i];
		sum += a[i];
	}
	set<int> st;
	for(int i = 0; i <= n; i ++) {
		for(int j = 1; j <= n; j ++) {
			if(i == j) continue;
			dp[i] = (dp[i] | (dp[i] << a[j]));
			dp[i][a[j]] = 1;
		}
	}
	if(sum%2 || !dp[0][sum/2]) {
		cout << 0;
		return;
	}
	vector<int> ans;
	for(int i = 0; i <= sum/2; i ++) ord[i] = i;
	random_shuffle(ord , ord+sum/2+1);
	int t = 0;
	for(int i1 = 0; i1 <= sum/2; i1 ++) {
		t ++;
		int i = ord[i1];
		int ok = 1;
		for(int j = 1; j <= n; j ++) {
			t ++;
			int cur = sum-a[j]+i;
			if(cur%2 || !dp[j][cur/2]) {
				ok = 0;
				break;
			}
		}
		if(t == 1e8) {
			break;
		}
		if(ok) ans.push_back(i);
	}
	sort(all(ans));
	cout << ans.size() << '\n';
	for(auto to: ans) {
		cout << to << ' ';
	}
}
/*
5 5 5 5  15

*/
main() {
	file("subsequence");
    ios;
    int tt = 1;
    //cin >> tt;
    while(tt --) {
        solve();
    }
    return 0;
}

Compilation message

bootfall.cpp:72:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   72 | main() {
      |      ^
bootfall.cpp: In function 'int main()':
bootfall.cpp:4:48: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    4 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                         ~~~~~~~^~~~~~~~~~~~~~~~~~~~
bootfall.cpp:73:2: note: in expansion of macro 'file'
   73 |  file("subsequence");
      |  ^~~~
bootfall.cpp:4:77: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
    4 | #define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
      |                                                                      ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:73:2: note: in expansion of macro 'file'
   73 |  file("subsequence");
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 492 KB Output is correct
2 Correct 1 ms 492 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Incorrect 1 ms 492 KB Output isn't correct
5 Halted 0 ms 0 KB -