답안 #663549

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
663549 2022-11-27T02:44:00 Z Ninja_Kunai Bootfall (IZhO17_bootfall) C++14
28 / 100
1000 ms 924 KB
/**
*    Author :  Nguyen Tuan Vu
*    Created : 27.11.2022
**/
 
#pragma GCC optimize("O3")
#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#define MASK(x) ((1)<<(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 jdg(chrono::steady_clock::now().time_since_epoch().count());
int Rand(int l, int r) {return l + jdg() % (r - l + 1);}
 
void file(){
    #define TASK "TASK"
    if(fopen(TASK".in", "r")) {
        freopen(TASK".in", "r", stdin);
        freopen(TASK".out", "w", stdout);
    }
}
 
const int N = 5e2 + 5;
const int M = 5e2 * 5e2;
int n, a[N], b[N];
bitset <2 * M + 5> dp[2];
 
bitset <2 * M + 5> calc(int n) {
	dp[0].reset(); dp[1].reset();
	dp[0][M] = 1;
	REP(i, n) {
		dp[(i + 1) & 1] |= dp[i & 1] << b[i + 1];
		dp[(i + 1) & 1] |= dp[i & 1] >> b[i + 1];
 
		dp[i & 1].reset();
	}
 
	return dp[n & 1];
}
 
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    file();
    cin >> n;
    FOR(i, 1, n) cin >> a[i], b[i] = a[i];
    if (calc(n)[M] == 0) return cout << 0, 0;
    bitset <2 * M + 5> tmp;
    FOR(i, 0, 2 * M) tmp[i] = 1;
    FOR(i, 1, n) {
    	int cnt = 0;
    	FOR(j, 1, n) if (i != j) b[++cnt] = a[j];
    	tmp &= calc(n - 1);
    }
 
    vector <int> ans;
    FOR(i, 0, 2 * M) if (tmp[i]) ans.push_back(abs(i - M));
    sort (ALL(ans)); ans.erase(unique(ALL(ans)), ans.end());
    cout << ans.size() << '\n';
    for (auto x : ans) cout << x << ' ';
    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".in", "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 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 6 ms 688 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 6 ms 688 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 23 ms 688 KB Output is correct
11 Correct 22 ms 596 KB Output is correct
12 Correct 27 ms 688 KB Output is correct
13 Correct 21 ms 692 KB Output is correct
14 Correct 21 ms 684 KB Output is correct
15 Correct 21 ms 688 KB Output is correct
16 Correct 23 ms 688 KB Output is correct
17 Correct 9 ms 596 KB Output is correct
18 Correct 15 ms 692 KB Output is correct
19 Correct 18 ms 596 KB Output is correct
20 Correct 26 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 6 ms 688 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 23 ms 688 KB Output is correct
11 Correct 22 ms 596 KB Output is correct
12 Correct 27 ms 688 KB Output is correct
13 Correct 21 ms 692 KB Output is correct
14 Correct 21 ms 684 KB Output is correct
15 Correct 21 ms 688 KB Output is correct
16 Correct 23 ms 688 KB Output is correct
17 Correct 9 ms 596 KB Output is correct
18 Correct 15 ms 692 KB Output is correct
19 Correct 18 ms 596 KB Output is correct
20 Correct 26 ms 692 KB Output is correct
21 Correct 100 ms 680 KB Output is correct
22 Correct 132 ms 672 KB Output is correct
23 Correct 59 ms 684 KB Output is correct
24 Correct 213 ms 668 KB Output is correct
25 Correct 208 ms 676 KB Output is correct
26 Correct 235 ms 668 KB Output is correct
27 Correct 235 ms 672 KB Output is correct
28 Correct 225 ms 680 KB Output is correct
29 Correct 233 ms 680 KB Output is correct
30 Correct 229 ms 668 KB Output is correct
31 Correct 232 ms 676 KB Output is correct
32 Correct 229 ms 676 KB Output is correct
33 Correct 242 ms 716 KB Output is correct
34 Correct 229 ms 668 KB Output is correct
35 Correct 241 ms 596 KB Output is correct
36 Correct 232 ms 668 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 6 ms 688 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 23 ms 688 KB Output is correct
11 Correct 22 ms 596 KB Output is correct
12 Correct 27 ms 688 KB Output is correct
13 Correct 21 ms 692 KB Output is correct
14 Correct 21 ms 684 KB Output is correct
15 Correct 21 ms 688 KB Output is correct
16 Correct 23 ms 688 KB Output is correct
17 Correct 9 ms 596 KB Output is correct
18 Correct 15 ms 692 KB Output is correct
19 Correct 18 ms 596 KB Output is correct
20 Correct 26 ms 692 KB Output is correct
21 Correct 100 ms 680 KB Output is correct
22 Correct 132 ms 672 KB Output is correct
23 Correct 59 ms 684 KB Output is correct
24 Correct 213 ms 668 KB Output is correct
25 Correct 208 ms 676 KB Output is correct
26 Correct 235 ms 668 KB Output is correct
27 Correct 235 ms 672 KB Output is correct
28 Correct 225 ms 680 KB Output is correct
29 Correct 233 ms 680 KB Output is correct
30 Correct 229 ms 668 KB Output is correct
31 Correct 232 ms 676 KB Output is correct
32 Correct 229 ms 676 KB Output is correct
33 Correct 242 ms 716 KB Output is correct
34 Correct 229 ms 668 KB Output is correct
35 Correct 241 ms 596 KB Output is correct
36 Correct 232 ms 668 KB Output is correct
37 Correct 927 ms 924 KB Output is correct
38 Correct 931 ms 924 KB Output is correct
39 Execution timed out 1088 ms 596 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 6 ms 688 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 23 ms 688 KB Output is correct
11 Correct 22 ms 596 KB Output is correct
12 Correct 27 ms 688 KB Output is correct
13 Correct 21 ms 692 KB Output is correct
14 Correct 21 ms 684 KB Output is correct
15 Correct 21 ms 688 KB Output is correct
16 Correct 23 ms 688 KB Output is correct
17 Correct 9 ms 596 KB Output is correct
18 Correct 15 ms 692 KB Output is correct
19 Correct 18 ms 596 KB Output is correct
20 Correct 26 ms 692 KB Output is correct
21 Correct 100 ms 680 KB Output is correct
22 Correct 132 ms 672 KB Output is correct
23 Correct 59 ms 684 KB Output is correct
24 Correct 213 ms 668 KB Output is correct
25 Correct 208 ms 676 KB Output is correct
26 Correct 235 ms 668 KB Output is correct
27 Correct 235 ms 672 KB Output is correct
28 Correct 225 ms 680 KB Output is correct
29 Correct 233 ms 680 KB Output is correct
30 Correct 229 ms 668 KB Output is correct
31 Correct 232 ms 676 KB Output is correct
32 Correct 229 ms 676 KB Output is correct
33 Correct 242 ms 716 KB Output is correct
34 Correct 229 ms 668 KB Output is correct
35 Correct 241 ms 596 KB Output is correct
36 Correct 232 ms 668 KB Output is correct
37 Correct 927 ms 924 KB Output is correct
38 Correct 931 ms 924 KB Output is correct
39 Execution timed out 1088 ms 596 KB Time limit exceeded
40 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 2 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 2 ms 596 KB Output is correct
5 Correct 6 ms 688 KB Output is correct
6 Correct 3 ms 596 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 5 ms 596 KB Output is correct
9 Correct 4 ms 596 KB Output is correct
10 Correct 23 ms 688 KB Output is correct
11 Correct 22 ms 596 KB Output is correct
12 Correct 27 ms 688 KB Output is correct
13 Correct 21 ms 692 KB Output is correct
14 Correct 21 ms 684 KB Output is correct
15 Correct 21 ms 688 KB Output is correct
16 Correct 23 ms 688 KB Output is correct
17 Correct 9 ms 596 KB Output is correct
18 Correct 15 ms 692 KB Output is correct
19 Correct 18 ms 596 KB Output is correct
20 Correct 26 ms 692 KB Output is correct
21 Correct 100 ms 680 KB Output is correct
22 Correct 132 ms 672 KB Output is correct
23 Correct 59 ms 684 KB Output is correct
24 Correct 213 ms 668 KB Output is correct
25 Correct 208 ms 676 KB Output is correct
26 Correct 235 ms 668 KB Output is correct
27 Correct 235 ms 672 KB Output is correct
28 Correct 225 ms 680 KB Output is correct
29 Correct 233 ms 680 KB Output is correct
30 Correct 229 ms 668 KB Output is correct
31 Correct 232 ms 676 KB Output is correct
32 Correct 229 ms 676 KB Output is correct
33 Correct 242 ms 716 KB Output is correct
34 Correct 229 ms 668 KB Output is correct
35 Correct 241 ms 596 KB Output is correct
36 Correct 232 ms 668 KB Output is correct
37 Correct 927 ms 924 KB Output is correct
38 Correct 931 ms 924 KB Output is correct
39 Execution timed out 1088 ms 596 KB Time limit exceeded
40 Halted 0 ms 0 KB -