답안 #701063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
701063 2023-02-19T23:32:43 Z Ninja_Kunai Bootfall (IZhO17_bootfall) C++14
65 / 100
1000 ms 1248 KB
/**
*    Author :  Nguyen Tuan Vu
*    Created : 19.02.2023
**/

#pragma GCC optimize("O2")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define MASK(x) ((1ll)<<(x))
#define BIT(x, i) (((x)>>(i))&(1))
#define ALL(v)  (v).begin(), (v).end()
#define REP(i, n)  for (int i = 0, _n = (n); i < _n; ++i)
#define FOR(i, a, b)  for (int i = (a), _b = (b); i <= _b; ++i) 
#define FORD(i, b, a)  for (int i = (b), _a = (a); i >= _a; --i)
#define db(val) "["#val" = "<<(val)<<"] "
#define TIME  (1.0 * clock() / CLOCKS_PER_SEC)

template <class X, class Y> bool minimize(X &a, Y b) {
    if (a > b) return a = b, true;
    return false;
}
template <class X, class Y> bool maximize(X &a, Y b) {
    if (a < b) return a = b, true;
    return false;
}

using namespace std;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
long long Rand(long long l, long long r) {return l + rng() % (r - l + 1);}

void file(){
    #define TASK "GAME"
    if(fopen(TASK".inp", "r")) {
        freopen(TASK".inp", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }
}

const int N = 5e2 + 5;
int n, a[N];

namespace sub1 {
	const int LIM = 12 * 200 + 5;

	bitset <LIM * 2> dp, res;
	void solve() {
		sort (a + 1, a + n + 1);
		res[LIM - 5] = 1;
		FOR(i, 1, n) {
			res = (res << a[i]) | (res >> a[i]);
		}
		
		if (res[LIM - 5] == 0) return void (cout << 0);

		FOR(i, 1, n) if (a[i] != a[i - 1]) {
			dp.reset();
			dp[LIM - 5] = 1;

			FOR(j, 1, n) if (j != i) {
				dp = (dp << a[j]) | (dp >> a[j]);
			}

			if (i == 1) res = dp;
			else res = res & dp;
			if (res.count() == 0) {
				break;
			}
		}

		vector <int> ans;
		FOR(i, 0, 2 * LIM - 10) if (res[i]) ans.push_back({abs(i - (LIM - 5))});
		sort (ALL(ans)); ans.erase(unique(ALL(ans)), ans.end());
		cout << ans.size() << '\n';
		for (auto x : ans) cout << x << ' ';
	}
};

namespace sub2 {
	const int LIM = 30 * 20 + 5;

	bitset <LIM * 2> dp, res;
	void solve() {
		sort (a + 1, a + n + 1);
		res[LIM - 5] = 1;
		FOR(i, 1, n) {
			res = (res << a[i]) | (res >> a[i]);
		}
		
		if (res[LIM - 5] == 0) return void (cout << 0);

		FOR(i, 1, n) if (a[i] != a[i - 1]) {
			dp.reset();
			dp[LIM - 5] = 1;

			FOR(j, 1, n) if (j != i) {
				dp = (dp << a[j]) | (dp >> a[j]);
			}

			if (i == 1) res = dp;
			else res = res & dp;
			if (res.count() == 0) {
				break;
			}
		}

		vector <int> ans;
		FOR(i, 0, 2 * LIM - 10) if (res[i]) ans.push_back({abs(i - (LIM - 5))});
		sort (ALL(ans)); ans.erase(unique(ALL(ans)), ans.end());
		cout << ans.size() << '\n';
		for (auto x : ans) cout << x << ' ';
	}
};

namespace sub3 {
	const int LIM = 100 * 100 + 5;

	bitset <LIM * 2> dp, res;
	void solve() {
		sort (a + 1, a + n + 1);
		res[LIM - 5] = 1;
		FOR(i, 1, n) {
			res = (res << a[i]) | (res >> a[i]);
		}

		if (res[LIM - 5] == 0) return void (cout << 0);

		FOR(i, 1, n) if (a[i] != a[i - 1]) {
			dp.reset();
			dp[LIM - 5] = 1;

			FOR(j, 1, n) if (j != i) {
				dp = (dp << a[j]) | (dp >> a[j]);
			}

			if (i == 1) res = dp;
			else res = res & dp;
			if (res.count() == 0) {
				break;
			}
		}

		vector <int> ans;
		FOR(i, 0, 2 * LIM - 10) if (res[i]) ans.push_back({abs(i - (LIM - 5))});
		sort (ALL(ans)); ans.erase(unique(ALL(ans)), ans.end());
		cout << ans.size() << '\n';
		for (auto x : ans) cout << x << ' ';
	}
};

namespace sub4 {
	const int LIM = 270 * 270 + 5;

	bitset <LIM * 2> dp, res;
	void solve() {
		sort (a + 1, a + n + 1);
		res[LIM - 5] = 1;
		FOR(i, 1, n) {
			res = (res << a[i]) | (res >> a[i]);
		}
		
		if (res[LIM - 5] == 0) return void (cout << 0);

		FOR(i, 1, n) if (a[i] != a[i - 1]) {
			dp.reset();
			dp[LIM - 5] = 1;

			FOR(j, 1, n) if (j != i) {
				dp = (dp << a[j]) | (dp >> a[j]);
			}

			if (i == 1) res = dp;
			else res = res & dp;
			if (res.count() == 0) {
				break;
			}
		}

		vector <int> ans;
		FOR(i, 0, 2 * LIM - 10) if (res[i]) ans.push_back({abs(i - (LIM - 5))});
		sort (ALL(ans)); ans.erase(unique(ALL(ans)), ans.end());
		cout << ans.size() << '\n';
		for (auto x : ans) cout << x << ' ';
	}
};

namespace sub5 {
	const int LIM = 350 * 350 + 5;

	bitset <LIM * 2> dp, res;
	void solve() {
		sort (a + 1, a + n + 1);
		res[LIM - 5] = 1;
		FOR(i, 1, n) {
			res = (res << a[i]) | (res >> a[i]);
		}
		
		if (res[LIM - 5] == 0) return void (cout << 0);

		FOR(i, 1, n) if (a[i] != a[i - 1]) {
			dp.reset();
			dp[LIM - 5] = 1;

			FOR(j, 1, n) if (j != i) {
				dp = (dp << a[j]) | (dp >> a[j]);
			}

			if (i == 1) res = dp;
			else res = res & dp;
			if (res.count() == 0) {
				break;
			}
		}

		vector <int> ans;
		FOR(i, 0, 2 * LIM - 10) if (res[i]) ans.push_back({abs(i - (LIM - 5))});
		sort (ALL(ans)); ans.erase(unique(ALL(ans)), ans.end());
		cout << ans.size() << '\n';
		for (auto x : ans) cout << x << ' ';
	}
};
namespace sub6 {
	const int LIM = 500 * 500 + 5;

	bitset <LIM * 2> dp, res;
	void solve() {
		sort (a + 1, a + n + 1);
		res[LIM - 5] = 1;
		FOR(i, 1, n) {
			res = (res << a[i]) | (res >> a[i]);
		}
		
		if (res[LIM - 5] == 0) return void (cout << 0);

		FOR(i, 1, n) if (a[i] != a[i - 1]) {
			dp.reset();
			dp[LIM - 5] = 1;

			FOR(j, 1, n) if (j != i) {
				dp = (dp << a[j]) | (dp >> a[j]);
			}

			if (i == 1) res = dp;
			else res = res & dp;
			if (res.count() == 0) {
				break;
			}
		}

		vector <int> ans;
		FOR(i, 0, 2 * LIM - 10) if (res[i]) ans.push_back({abs(i - (LIM - 5))});
		sort (ALL(ans)); ans.erase(unique(ALL(ans)), ans.end());
		cout << ans.size() << '\n';
		for (auto x : ans) cout << x << ' ';
	}
};

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    file();
    cin >> n;
    FOR(i, 1, n) cin >> a[i];

    if (n <= 12 && *max_element(a + 1, a + n + 1) <= 200) sub1::solve();
    else if (n <= 30 && *max_element(a + 1, a + n + 1) <= 20) sub2::solve();
    else if (n <= 100 && *max_element(a + 1, a + n + 1) <= 100) sub3::solve();
    else if (n <= 270 && *max_element(a + 1, a + n + 1) <= 270) sub4::solve();
    else if (n <= 350 && *max_element(a + 1, a + n + 1) <= 350) sub5::solve();
    else if (n <= 500 && *max_element(a + 1, a + n + 1) <= 500) sub6::solve();
    cerr << "Time elapsed: " << TIME << " s.\n";
    return 0;
}

/*
==================================================+
INPUT:                                            |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
OUTPUT:                                           |
--------------------------------------------------|

--------------------------------------------------|
==================================================+
*/

Compilation message

bootfall.cpp: In function 'void file()':
bootfall.cpp:35:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         freopen(TASK".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:36:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   36 |         freopen(TASK".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 6 ms 340 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 7 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 6 ms 340 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 7 ms 340 KB Output is correct
37 Correct 73 ms 592 KB Output is correct
38 Correct 79 ms 596 KB Output is correct
39 Correct 5 ms 340 KB Output is correct
40 Correct 271 ms 668 KB Output is correct
41 Correct 5 ms 424 KB Output is correct
42 Correct 200 ms 664 KB Output is correct
43 Correct 51 ms 804 KB Output is correct
44 Correct 53 ms 796 KB Output is correct
45 Correct 56 ms 848 KB Output is correct
46 Correct 8 ms 340 KB Output is correct
47 Correct 199 ms 660 KB Output is correct
48 Correct 16 ms 804 KB Output is correct
49 Correct 9 ms 460 KB Output is correct
50 Correct 225 ms 660 KB Output is correct
51 Correct 3 ms 412 KB Output is correct
52 Correct 38 ms 928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 6 ms 340 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 7 ms 340 KB Output is correct
37 Correct 73 ms 592 KB Output is correct
38 Correct 79 ms 596 KB Output is correct
39 Correct 5 ms 340 KB Output is correct
40 Correct 271 ms 668 KB Output is correct
41 Correct 5 ms 424 KB Output is correct
42 Correct 200 ms 664 KB Output is correct
43 Correct 51 ms 804 KB Output is correct
44 Correct 53 ms 796 KB Output is correct
45 Correct 56 ms 848 KB Output is correct
46 Correct 8 ms 340 KB Output is correct
47 Correct 199 ms 660 KB Output is correct
48 Correct 16 ms 804 KB Output is correct
49 Correct 9 ms 460 KB Output is correct
50 Correct 225 ms 660 KB Output is correct
51 Correct 3 ms 412 KB Output is correct
52 Correct 38 ms 928 KB Output is correct
53 Correct 522 ms 856 KB Output is correct
54 Correct 566 ms 980 KB Output is correct
55 Correct 83 ms 1224 KB Output is correct
56 Correct 522 ms 1104 KB Output is correct
57 Correct 96 ms 1240 KB Output is correct
58 Correct 770 ms 980 KB Output is correct
59 Correct 435 ms 1112 KB Output is correct
60 Correct 6 ms 340 KB Output is correct
61 Correct 441 ms 1112 KB Output is correct
62 Correct 216 ms 1232 KB Output is correct
63 Correct 121 ms 1244 KB Output is correct
64 Correct 117 ms 1248 KB Output is correct
65 Correct 37 ms 468 KB Output is correct
66 Correct 142 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 336 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 340 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Correct 3 ms 332 KB Output is correct
22 Correct 4 ms 332 KB Output is correct
23 Correct 2 ms 340 KB Output is correct
24 Correct 6 ms 340 KB Output is correct
25 Correct 2 ms 336 KB Output is correct
26 Correct 3 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 1 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 6 ms 344 KB Output is correct
33 Correct 1 ms 340 KB Output is correct
34 Correct 1 ms 340 KB Output is correct
35 Correct 1 ms 340 KB Output is correct
36 Correct 7 ms 340 KB Output is correct
37 Correct 73 ms 592 KB Output is correct
38 Correct 79 ms 596 KB Output is correct
39 Correct 5 ms 340 KB Output is correct
40 Correct 271 ms 668 KB Output is correct
41 Correct 5 ms 424 KB Output is correct
42 Correct 200 ms 664 KB Output is correct
43 Correct 51 ms 804 KB Output is correct
44 Correct 53 ms 796 KB Output is correct
45 Correct 56 ms 848 KB Output is correct
46 Correct 8 ms 340 KB Output is correct
47 Correct 199 ms 660 KB Output is correct
48 Correct 16 ms 804 KB Output is correct
49 Correct 9 ms 460 KB Output is correct
50 Correct 225 ms 660 KB Output is correct
51 Correct 3 ms 412 KB Output is correct
52 Correct 38 ms 928 KB Output is correct
53 Correct 522 ms 856 KB Output is correct
54 Correct 566 ms 980 KB Output is correct
55 Correct 83 ms 1224 KB Output is correct
56 Correct 522 ms 1104 KB Output is correct
57 Correct 96 ms 1240 KB Output is correct
58 Correct 770 ms 980 KB Output is correct
59 Correct 435 ms 1112 KB Output is correct
60 Correct 6 ms 340 KB Output is correct
61 Correct 441 ms 1112 KB Output is correct
62 Correct 216 ms 1232 KB Output is correct
63 Correct 121 ms 1244 KB Output is correct
64 Correct 117 ms 1248 KB Output is correct
65 Correct 37 ms 468 KB Output is correct
66 Correct 142 ms 596 KB Output is correct
67 Execution timed out 1072 ms 596 KB Time limit exceeded
68 Halted 0 ms 0 KB -