Submission #343381

# Submission time Handle Problem Language Result Execution time Memory
343381 2021-01-03T20:05:06 Z Kalashnikov Bootfall (IZhO17_bootfall) C++17
65 / 100
1000 ms 7900 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 < 500*260; i ++) ord[i] = i;
	random_shuffle(ord , ord+500*260);
	for(int i1 = 0; i1 < 500*260 && i1 < (int)(1e8/n); i1 ++) {
		int i = ord[i1];
		int ok = 1;
		for(int j = 1; j <= n; j ++) {
			int cur = sum-a[j]+i;
			if(cur%2 || !dp[j][cur/2]) {
				ok = 0;
				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:66:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   66 | 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:67:2: note: in expansion of macro 'file'
   67 |  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:67:2: note: in expansion of macro 'file'
   67 |  file("subsequence");
      |  ^~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1004 KB Output is correct
2 Correct 5 ms 1132 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 4 ms 1024 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1016 KB Output is correct
7 Correct 5 ms 1004 KB Output is correct
8 Correct 5 ms 1132 KB Output is correct
9 Correct 5 ms 1004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1004 KB Output is correct
2 Correct 5 ms 1132 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 4 ms 1024 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1016 KB Output is correct
7 Correct 5 ms 1004 KB Output is correct
8 Correct 5 ms 1132 KB Output is correct
9 Correct 5 ms 1004 KB Output is correct
10 Correct 9 ms 1388 KB Output is correct
11 Correct 9 ms 1388 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 10 ms 1260 KB Output is correct
14 Correct 9 ms 1388 KB Output is correct
15 Correct 11 ms 1388 KB Output is correct
16 Correct 9 ms 1516 KB Output is correct
17 Correct 6 ms 1132 KB Output is correct
18 Correct 7 ms 1260 KB Output is correct
19 Correct 8 ms 1260 KB Output is correct
20 Correct 9 ms 1388 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1004 KB Output is correct
2 Correct 5 ms 1132 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 4 ms 1024 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1016 KB Output is correct
7 Correct 5 ms 1004 KB Output is correct
8 Correct 5 ms 1132 KB Output is correct
9 Correct 5 ms 1004 KB Output is correct
10 Correct 9 ms 1388 KB Output is correct
11 Correct 9 ms 1388 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 10 ms 1260 KB Output is correct
14 Correct 9 ms 1388 KB Output is correct
15 Correct 11 ms 1388 KB Output is correct
16 Correct 9 ms 1516 KB Output is correct
17 Correct 6 ms 1132 KB Output is correct
18 Correct 7 ms 1260 KB Output is correct
19 Correct 8 ms 1260 KB Output is correct
20 Correct 9 ms 1388 KB Output is correct
21 Correct 27 ms 1900 KB Output is correct
22 Correct 34 ms 2156 KB Output is correct
23 Correct 19 ms 1772 KB Output is correct
24 Correct 55 ms 2540 KB Output is correct
25 Correct 54 ms 2412 KB Output is correct
26 Correct 67 ms 2540 KB Output is correct
27 Correct 58 ms 2540 KB Output is correct
28 Correct 59 ms 2668 KB Output is correct
29 Correct 60 ms 2552 KB Output is correct
30 Correct 58 ms 2540 KB Output is correct
31 Correct 59 ms 2540 KB Output is correct
32 Correct 74 ms 2540 KB Output is correct
33 Correct 64 ms 2540 KB Output is correct
34 Correct 62 ms 2540 KB Output is correct
35 Correct 58 ms 2540 KB Output is correct
36 Correct 59 ms 2540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1004 KB Output is correct
2 Correct 5 ms 1132 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 4 ms 1024 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1016 KB Output is correct
7 Correct 5 ms 1004 KB Output is correct
8 Correct 5 ms 1132 KB Output is correct
9 Correct 5 ms 1004 KB Output is correct
10 Correct 9 ms 1388 KB Output is correct
11 Correct 9 ms 1388 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 10 ms 1260 KB Output is correct
14 Correct 9 ms 1388 KB Output is correct
15 Correct 11 ms 1388 KB Output is correct
16 Correct 9 ms 1516 KB Output is correct
17 Correct 6 ms 1132 KB Output is correct
18 Correct 7 ms 1260 KB Output is correct
19 Correct 8 ms 1260 KB Output is correct
20 Correct 9 ms 1388 KB Output is correct
21 Correct 27 ms 1900 KB Output is correct
22 Correct 34 ms 2156 KB Output is correct
23 Correct 19 ms 1772 KB Output is correct
24 Correct 55 ms 2540 KB Output is correct
25 Correct 54 ms 2412 KB Output is correct
26 Correct 67 ms 2540 KB Output is correct
27 Correct 58 ms 2540 KB Output is correct
28 Correct 59 ms 2668 KB Output is correct
29 Correct 60 ms 2552 KB Output is correct
30 Correct 58 ms 2540 KB Output is correct
31 Correct 59 ms 2540 KB Output is correct
32 Correct 74 ms 2540 KB Output is correct
33 Correct 64 ms 2540 KB Output is correct
34 Correct 62 ms 2540 KB Output is correct
35 Correct 58 ms 2540 KB Output is correct
36 Correct 59 ms 2540 KB Output is correct
37 Correct 226 ms 4204 KB Output is correct
38 Correct 227 ms 4228 KB Output is correct
39 Correct 328 ms 4844 KB Output is correct
40 Correct 409 ms 5484 KB Output is correct
41 Correct 401 ms 5164 KB Output is correct
42 Correct 364 ms 5148 KB Output is correct
43 Correct 348 ms 5356 KB Output is correct
44 Correct 364 ms 5260 KB Output is correct
45 Correct 363 ms 5228 KB Output is correct
46 Correct 410 ms 5228 KB Output is correct
47 Correct 355 ms 5100 KB Output is correct
48 Correct 355 ms 5356 KB Output is correct
49 Correct 344 ms 4972 KB Output is correct
50 Correct 358 ms 5100 KB Output is correct
51 Correct 336 ms 4332 KB Output is correct
52 Correct 422 ms 5612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1004 KB Output is correct
2 Correct 5 ms 1132 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 4 ms 1024 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1016 KB Output is correct
7 Correct 5 ms 1004 KB Output is correct
8 Correct 5 ms 1132 KB Output is correct
9 Correct 5 ms 1004 KB Output is correct
10 Correct 9 ms 1388 KB Output is correct
11 Correct 9 ms 1388 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 10 ms 1260 KB Output is correct
14 Correct 9 ms 1388 KB Output is correct
15 Correct 11 ms 1388 KB Output is correct
16 Correct 9 ms 1516 KB Output is correct
17 Correct 6 ms 1132 KB Output is correct
18 Correct 7 ms 1260 KB Output is correct
19 Correct 8 ms 1260 KB Output is correct
20 Correct 9 ms 1388 KB Output is correct
21 Correct 27 ms 1900 KB Output is correct
22 Correct 34 ms 2156 KB Output is correct
23 Correct 19 ms 1772 KB Output is correct
24 Correct 55 ms 2540 KB Output is correct
25 Correct 54 ms 2412 KB Output is correct
26 Correct 67 ms 2540 KB Output is correct
27 Correct 58 ms 2540 KB Output is correct
28 Correct 59 ms 2668 KB Output is correct
29 Correct 60 ms 2552 KB Output is correct
30 Correct 58 ms 2540 KB Output is correct
31 Correct 59 ms 2540 KB Output is correct
32 Correct 74 ms 2540 KB Output is correct
33 Correct 64 ms 2540 KB Output is correct
34 Correct 62 ms 2540 KB Output is correct
35 Correct 58 ms 2540 KB Output is correct
36 Correct 59 ms 2540 KB Output is correct
37 Correct 226 ms 4204 KB Output is correct
38 Correct 227 ms 4228 KB Output is correct
39 Correct 328 ms 4844 KB Output is correct
40 Correct 409 ms 5484 KB Output is correct
41 Correct 401 ms 5164 KB Output is correct
42 Correct 364 ms 5148 KB Output is correct
43 Correct 348 ms 5356 KB Output is correct
44 Correct 364 ms 5260 KB Output is correct
45 Correct 363 ms 5228 KB Output is correct
46 Correct 410 ms 5228 KB Output is correct
47 Correct 355 ms 5100 KB Output is correct
48 Correct 355 ms 5356 KB Output is correct
49 Correct 344 ms 4972 KB Output is correct
50 Correct 358 ms 5100 KB Output is correct
51 Correct 336 ms 4332 KB Output is correct
52 Correct 422 ms 5612 KB Output is correct
53 Correct 516 ms 5996 KB Output is correct
54 Correct 696 ms 7132 KB Output is correct
55 Correct 727 ms 7152 KB Output is correct
56 Correct 543 ms 6252 KB Output is correct
57 Correct 741 ms 7128 KB Output is correct
58 Correct 700 ms 7020 KB Output is correct
59 Correct 774 ms 7048 KB Output is correct
60 Correct 657 ms 6124 KB Output is correct
61 Correct 724 ms 7176 KB Output is correct
62 Correct 608 ms 6640 KB Output is correct
63 Correct 626 ms 6640 KB Output is correct
64 Correct 608 ms 6512 KB Output is correct
65 Correct 536 ms 6124 KB Output is correct
66 Correct 519 ms 5868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1004 KB Output is correct
2 Correct 5 ms 1132 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 4 ms 1024 KB Output is correct
5 Correct 5 ms 1152 KB Output is correct
6 Correct 5 ms 1016 KB Output is correct
7 Correct 5 ms 1004 KB Output is correct
8 Correct 5 ms 1132 KB Output is correct
9 Correct 5 ms 1004 KB Output is correct
10 Correct 9 ms 1388 KB Output is correct
11 Correct 9 ms 1388 KB Output is correct
12 Correct 11 ms 1388 KB Output is correct
13 Correct 10 ms 1260 KB Output is correct
14 Correct 9 ms 1388 KB Output is correct
15 Correct 11 ms 1388 KB Output is correct
16 Correct 9 ms 1516 KB Output is correct
17 Correct 6 ms 1132 KB Output is correct
18 Correct 7 ms 1260 KB Output is correct
19 Correct 8 ms 1260 KB Output is correct
20 Correct 9 ms 1388 KB Output is correct
21 Correct 27 ms 1900 KB Output is correct
22 Correct 34 ms 2156 KB Output is correct
23 Correct 19 ms 1772 KB Output is correct
24 Correct 55 ms 2540 KB Output is correct
25 Correct 54 ms 2412 KB Output is correct
26 Correct 67 ms 2540 KB Output is correct
27 Correct 58 ms 2540 KB Output is correct
28 Correct 59 ms 2668 KB Output is correct
29 Correct 60 ms 2552 KB Output is correct
30 Correct 58 ms 2540 KB Output is correct
31 Correct 59 ms 2540 KB Output is correct
32 Correct 74 ms 2540 KB Output is correct
33 Correct 64 ms 2540 KB Output is correct
34 Correct 62 ms 2540 KB Output is correct
35 Correct 58 ms 2540 KB Output is correct
36 Correct 59 ms 2540 KB Output is correct
37 Correct 226 ms 4204 KB Output is correct
38 Correct 227 ms 4228 KB Output is correct
39 Correct 328 ms 4844 KB Output is correct
40 Correct 409 ms 5484 KB Output is correct
41 Correct 401 ms 5164 KB Output is correct
42 Correct 364 ms 5148 KB Output is correct
43 Correct 348 ms 5356 KB Output is correct
44 Correct 364 ms 5260 KB Output is correct
45 Correct 363 ms 5228 KB Output is correct
46 Correct 410 ms 5228 KB Output is correct
47 Correct 355 ms 5100 KB Output is correct
48 Correct 355 ms 5356 KB Output is correct
49 Correct 344 ms 4972 KB Output is correct
50 Correct 358 ms 5100 KB Output is correct
51 Correct 336 ms 4332 KB Output is correct
52 Correct 422 ms 5612 KB Output is correct
53 Correct 516 ms 5996 KB Output is correct
54 Correct 696 ms 7132 KB Output is correct
55 Correct 727 ms 7152 KB Output is correct
56 Correct 543 ms 6252 KB Output is correct
57 Correct 741 ms 7128 KB Output is correct
58 Correct 700 ms 7020 KB Output is correct
59 Correct 774 ms 7048 KB Output is correct
60 Correct 657 ms 6124 KB Output is correct
61 Correct 724 ms 7176 KB Output is correct
62 Correct 608 ms 6640 KB Output is correct
63 Correct 626 ms 6640 KB Output is correct
64 Correct 608 ms 6512 KB Output is correct
65 Correct 536 ms 6124 KB Output is correct
66 Correct 519 ms 5868 KB Output is correct
67 Correct 945 ms 7900 KB Output is correct
68 Execution timed out 1085 ms 6928 KB Time limit exceeded
69 Halted 0 ms 0 KB -