답안 #519782

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
519782 2022-01-27T10:30:56 Z Dasha_Gnedko Bootfall (IZhO17_bootfall) C++17
100 / 100
488 ms 3776 KB
#include <bits/stdc++.h>

//#include <ext/pb_ds/detail/standard_policies.hpp>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx2")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

using namespace std;

//using namespace __gnu_pbds;
//template <typename T> using ordered_set = tree <T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update>;

mt19937 gen(time(0));

#define ll long long
#define ld long double
#define pb push_back
#define F first
#define S second
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define sz(a) int32_t(a.size())
#define endl '\n'
//#define int long long

const int N = 250100;
const int M = 31;
const int mod = 1e9 + 7;
const ll inf = 1e18 + 7;

int dp[N], ans[N], a[510];
bool cnt[N];

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("input.txt", "r", stdin);
//    freopen("output.txt", "w", stdout);
#endif // LOCAL

    int n;
    cin >> n;
    int sum = 0;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    dp[0] = 1;
    for(int i = 0; i < n; i++)
    {
        for(int j = N - 1; j >= a[i]; j--)
            dp[j] += dp[j - a[i]];
    }
    if (sum % 2 || !dp[sum / 2])
    {
        cout << 0;
        return 0;
    }
    for(int i = 0; i < n; i++)
    {
        for(int j = a[i]; j < N; j++)
            dp[j] -= dp[j - a[i]];
        for(int j = N - 1; j >= 0; j--)
        {
            if (!dp[j]) continue;
            int x = j, y = sum - j - a[i];
            cnt[abs(x - y)] = 1;
        }
        for(int i = 0; i < N; i++)
        {
            if (cnt[i]) ans[i]++;
            cnt[i] = 0;
        }
        for(int j = N - 1; j >= a[i]; j--)
            dp[j] += dp[j - a[i]];
    }
    vector < int > ot;
    for(int i = 1; i < N; i++)
        if (ans[i] == n) ot.pb(i);
    cout << sz(ot) << endl;
    for(auto to: ot)
        cout << to << " ";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1472 KB Output is correct
2 Correct 8 ms 1480 KB Output is correct
3 Correct 1 ms 1232 KB Output is correct
4 Correct 8 ms 1552 KB Output is correct
5 Correct 16 ms 1488 KB Output is correct
6 Correct 8 ms 1488 KB Output is correct
7 Correct 7 ms 1488 KB Output is correct
8 Correct 13 ms 1556 KB Output is correct
9 Correct 10 ms 1488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1472 KB Output is correct
2 Correct 8 ms 1480 KB Output is correct
3 Correct 1 ms 1232 KB Output is correct
4 Correct 8 ms 1552 KB Output is correct
5 Correct 16 ms 1488 KB Output is correct
6 Correct 8 ms 1488 KB Output is correct
7 Correct 7 ms 1488 KB Output is correct
8 Correct 13 ms 1556 KB Output is correct
9 Correct 10 ms 1488 KB Output is correct
10 Correct 27 ms 1480 KB Output is correct
11 Correct 29 ms 1488 KB Output is correct
12 Correct 30 ms 1544 KB Output is correct
13 Correct 32 ms 1488 KB Output is correct
14 Correct 26 ms 1488 KB Output is correct
15 Correct 38 ms 1488 KB Output is correct
16 Correct 30 ms 1532 KB Output is correct
17 Correct 17 ms 1488 KB Output is correct
18 Correct 24 ms 1488 KB Output is correct
19 Correct 24 ms 1488 KB Output is correct
20 Correct 31 ms 1488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1472 KB Output is correct
2 Correct 8 ms 1480 KB Output is correct
3 Correct 1 ms 1232 KB Output is correct
4 Correct 8 ms 1552 KB Output is correct
5 Correct 16 ms 1488 KB Output is correct
6 Correct 8 ms 1488 KB Output is correct
7 Correct 7 ms 1488 KB Output is correct
8 Correct 13 ms 1556 KB Output is correct
9 Correct 10 ms 1488 KB Output is correct
10 Correct 27 ms 1480 KB Output is correct
11 Correct 29 ms 1488 KB Output is correct
12 Correct 30 ms 1544 KB Output is correct
13 Correct 32 ms 1488 KB Output is correct
14 Correct 26 ms 1488 KB Output is correct
15 Correct 38 ms 1488 KB Output is correct
16 Correct 30 ms 1532 KB Output is correct
17 Correct 17 ms 1488 KB Output is correct
18 Correct 24 ms 1488 KB Output is correct
19 Correct 24 ms 1488 KB Output is correct
20 Correct 31 ms 1488 KB Output is correct
21 Correct 57 ms 1540 KB Output is correct
22 Correct 69 ms 1488 KB Output is correct
23 Correct 45 ms 1560 KB Output is correct
24 Correct 81 ms 1556 KB Output is correct
25 Correct 110 ms 1576 KB Output is correct
26 Correct 98 ms 1572 KB Output is correct
27 Correct 95 ms 1568 KB Output is correct
28 Correct 89 ms 1568 KB Output is correct
29 Correct 102 ms 1560 KB Output is correct
30 Correct 88 ms 1564 KB Output is correct
31 Correct 94 ms 1560 KB Output is correct
32 Correct 102 ms 1544 KB Output is correct
33 Correct 94 ms 1564 KB Output is correct
34 Correct 93 ms 1488 KB Output is correct
35 Correct 122 ms 1564 KB Output is correct
36 Correct 103 ms 1552 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1472 KB Output is correct
2 Correct 8 ms 1480 KB Output is correct
3 Correct 1 ms 1232 KB Output is correct
4 Correct 8 ms 1552 KB Output is correct
5 Correct 16 ms 1488 KB Output is correct
6 Correct 8 ms 1488 KB Output is correct
7 Correct 7 ms 1488 KB Output is correct
8 Correct 13 ms 1556 KB Output is correct
9 Correct 10 ms 1488 KB Output is correct
10 Correct 27 ms 1480 KB Output is correct
11 Correct 29 ms 1488 KB Output is correct
12 Correct 30 ms 1544 KB Output is correct
13 Correct 32 ms 1488 KB Output is correct
14 Correct 26 ms 1488 KB Output is correct
15 Correct 38 ms 1488 KB Output is correct
16 Correct 30 ms 1532 KB Output is correct
17 Correct 17 ms 1488 KB Output is correct
18 Correct 24 ms 1488 KB Output is correct
19 Correct 24 ms 1488 KB Output is correct
20 Correct 31 ms 1488 KB Output is correct
21 Correct 57 ms 1540 KB Output is correct
22 Correct 69 ms 1488 KB Output is correct
23 Correct 45 ms 1560 KB Output is correct
24 Correct 81 ms 1556 KB Output is correct
25 Correct 110 ms 1576 KB Output is correct
26 Correct 98 ms 1572 KB Output is correct
27 Correct 95 ms 1568 KB Output is correct
28 Correct 89 ms 1568 KB Output is correct
29 Correct 102 ms 1560 KB Output is correct
30 Correct 88 ms 1564 KB Output is correct
31 Correct 94 ms 1560 KB Output is correct
32 Correct 102 ms 1544 KB Output is correct
33 Correct 94 ms 1564 KB Output is correct
34 Correct 93 ms 1488 KB Output is correct
35 Correct 122 ms 1564 KB Output is correct
36 Correct 103 ms 1552 KB Output is correct
37 Correct 167 ms 1680 KB Output is correct
38 Correct 182 ms 1736 KB Output is correct
39 Correct 210 ms 1764 KB Output is correct
40 Correct 222 ms 1788 KB Output is correct
41 Correct 224 ms 1808 KB Output is correct
42 Correct 231 ms 1780 KB Output is correct
43 Correct 207 ms 1996 KB Output is correct
44 Correct 218 ms 2120 KB Output is correct
45 Correct 210 ms 2132 KB Output is correct
46 Correct 230 ms 1648 KB Output is correct
47 Correct 226 ms 1780 KB Output is correct
48 Correct 217 ms 2052 KB Output is correct
49 Correct 212 ms 1764 KB Output is correct
50 Correct 216 ms 1844 KB Output is correct
51 Correct 30 ms 1288 KB Output is correct
52 Correct 239 ms 2180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1472 KB Output is correct
2 Correct 8 ms 1480 KB Output is correct
3 Correct 1 ms 1232 KB Output is correct
4 Correct 8 ms 1552 KB Output is correct
5 Correct 16 ms 1488 KB Output is correct
6 Correct 8 ms 1488 KB Output is correct
7 Correct 7 ms 1488 KB Output is correct
8 Correct 13 ms 1556 KB Output is correct
9 Correct 10 ms 1488 KB Output is correct
10 Correct 27 ms 1480 KB Output is correct
11 Correct 29 ms 1488 KB Output is correct
12 Correct 30 ms 1544 KB Output is correct
13 Correct 32 ms 1488 KB Output is correct
14 Correct 26 ms 1488 KB Output is correct
15 Correct 38 ms 1488 KB Output is correct
16 Correct 30 ms 1532 KB Output is correct
17 Correct 17 ms 1488 KB Output is correct
18 Correct 24 ms 1488 KB Output is correct
19 Correct 24 ms 1488 KB Output is correct
20 Correct 31 ms 1488 KB Output is correct
21 Correct 57 ms 1540 KB Output is correct
22 Correct 69 ms 1488 KB Output is correct
23 Correct 45 ms 1560 KB Output is correct
24 Correct 81 ms 1556 KB Output is correct
25 Correct 110 ms 1576 KB Output is correct
26 Correct 98 ms 1572 KB Output is correct
27 Correct 95 ms 1568 KB Output is correct
28 Correct 89 ms 1568 KB Output is correct
29 Correct 102 ms 1560 KB Output is correct
30 Correct 88 ms 1564 KB Output is correct
31 Correct 94 ms 1560 KB Output is correct
32 Correct 102 ms 1544 KB Output is correct
33 Correct 94 ms 1564 KB Output is correct
34 Correct 93 ms 1488 KB Output is correct
35 Correct 122 ms 1564 KB Output is correct
36 Correct 103 ms 1552 KB Output is correct
37 Correct 167 ms 1680 KB Output is correct
38 Correct 182 ms 1736 KB Output is correct
39 Correct 210 ms 1764 KB Output is correct
40 Correct 222 ms 1788 KB Output is correct
41 Correct 224 ms 1808 KB Output is correct
42 Correct 231 ms 1780 KB Output is correct
43 Correct 207 ms 1996 KB Output is correct
44 Correct 218 ms 2120 KB Output is correct
45 Correct 210 ms 2132 KB Output is correct
46 Correct 230 ms 1648 KB Output is correct
47 Correct 226 ms 1780 KB Output is correct
48 Correct 217 ms 2052 KB Output is correct
49 Correct 212 ms 1764 KB Output is correct
50 Correct 216 ms 1844 KB Output is correct
51 Correct 30 ms 1288 KB Output is correct
52 Correct 239 ms 2180 KB Output is correct
53 Correct 256 ms 1992 KB Output is correct
54 Correct 299 ms 2120 KB Output is correct
55 Correct 303 ms 2472 KB Output is correct
56 Correct 258 ms 2060 KB Output is correct
57 Correct 344 ms 2624 KB Output is correct
58 Correct 309 ms 2148 KB Output is correct
59 Correct 308 ms 2312 KB Output is correct
60 Correct 41 ms 1232 KB Output is correct
61 Correct 305 ms 2500 KB Output is correct
62 Correct 277 ms 2416 KB Output is correct
63 Correct 276 ms 2444 KB Output is correct
64 Correct 271 ms 2468 KB Output is correct
65 Correct 266 ms 1684 KB Output is correct
66 Correct 260 ms 1740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1472 KB Output is correct
2 Correct 8 ms 1480 KB Output is correct
3 Correct 1 ms 1232 KB Output is correct
4 Correct 8 ms 1552 KB Output is correct
5 Correct 16 ms 1488 KB Output is correct
6 Correct 8 ms 1488 KB Output is correct
7 Correct 7 ms 1488 KB Output is correct
8 Correct 13 ms 1556 KB Output is correct
9 Correct 10 ms 1488 KB Output is correct
10 Correct 27 ms 1480 KB Output is correct
11 Correct 29 ms 1488 KB Output is correct
12 Correct 30 ms 1544 KB Output is correct
13 Correct 32 ms 1488 KB Output is correct
14 Correct 26 ms 1488 KB Output is correct
15 Correct 38 ms 1488 KB Output is correct
16 Correct 30 ms 1532 KB Output is correct
17 Correct 17 ms 1488 KB Output is correct
18 Correct 24 ms 1488 KB Output is correct
19 Correct 24 ms 1488 KB Output is correct
20 Correct 31 ms 1488 KB Output is correct
21 Correct 57 ms 1540 KB Output is correct
22 Correct 69 ms 1488 KB Output is correct
23 Correct 45 ms 1560 KB Output is correct
24 Correct 81 ms 1556 KB Output is correct
25 Correct 110 ms 1576 KB Output is correct
26 Correct 98 ms 1572 KB Output is correct
27 Correct 95 ms 1568 KB Output is correct
28 Correct 89 ms 1568 KB Output is correct
29 Correct 102 ms 1560 KB Output is correct
30 Correct 88 ms 1564 KB Output is correct
31 Correct 94 ms 1560 KB Output is correct
32 Correct 102 ms 1544 KB Output is correct
33 Correct 94 ms 1564 KB Output is correct
34 Correct 93 ms 1488 KB Output is correct
35 Correct 122 ms 1564 KB Output is correct
36 Correct 103 ms 1552 KB Output is correct
37 Correct 167 ms 1680 KB Output is correct
38 Correct 182 ms 1736 KB Output is correct
39 Correct 210 ms 1764 KB Output is correct
40 Correct 222 ms 1788 KB Output is correct
41 Correct 224 ms 1808 KB Output is correct
42 Correct 231 ms 1780 KB Output is correct
43 Correct 207 ms 1996 KB Output is correct
44 Correct 218 ms 2120 KB Output is correct
45 Correct 210 ms 2132 KB Output is correct
46 Correct 230 ms 1648 KB Output is correct
47 Correct 226 ms 1780 KB Output is correct
48 Correct 217 ms 2052 KB Output is correct
49 Correct 212 ms 1764 KB Output is correct
50 Correct 216 ms 1844 KB Output is correct
51 Correct 30 ms 1288 KB Output is correct
52 Correct 239 ms 2180 KB Output is correct
53 Correct 256 ms 1992 KB Output is correct
54 Correct 299 ms 2120 KB Output is correct
55 Correct 303 ms 2472 KB Output is correct
56 Correct 258 ms 2060 KB Output is correct
57 Correct 344 ms 2624 KB Output is correct
58 Correct 309 ms 2148 KB Output is correct
59 Correct 308 ms 2312 KB Output is correct
60 Correct 41 ms 1232 KB Output is correct
61 Correct 305 ms 2500 KB Output is correct
62 Correct 277 ms 2416 KB Output is correct
63 Correct 276 ms 2444 KB Output is correct
64 Correct 271 ms 2468 KB Output is correct
65 Correct 266 ms 1684 KB Output is correct
66 Correct 260 ms 1740 KB Output is correct
67 Correct 347 ms 2356 KB Output is correct
68 Correct 58 ms 1232 KB Output is correct
69 Correct 485 ms 3504 KB Output is correct
70 Correct 443 ms 2796 KB Output is correct
71 Correct 432 ms 2884 KB Output is correct
72 Correct 481 ms 2024 KB Output is correct
73 Correct 453 ms 1928 KB Output is correct
74 Correct 485 ms 3680 KB Output is correct
75 Correct 447 ms 3232 KB Output is correct
76 Correct 488 ms 3632 KB Output is correct
77 Correct 479 ms 3776 KB Output is correct