답안 #1107873

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1107873 2024-11-02T09:06:59 Z Tymond Bootfall (IZhO17_bootfall) C++17
100 / 100
590 ms 3600 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define vi vector<int>
#define vll vector<long long>
#define pii pair<int, int>
#define pll pair<long long, long long>
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::high_resolution_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
#ifdef DEBUG
auto&operator<<(auto&o,pair<auto,auto>p){return o<<"("<<p.first<<", "<<p.second<<")";}
auto operator<<(auto&o,auto x)->decltype(x.end(),o){o<<"{";int i=0;for(auto e:x)o<<","+!i++<<e;return o<<"}";}
#define debug(X...)cerr<<"["#X"]: ",[](auto...$){((cerr<<$<<"; "),...)<<endl;}(X)
#else
#define debug(...){}
#endif
 
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
 
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int MAXN = 510;
const int MOD = 1e9 + 7;
int f[MAXN * MAXN];
int dp[MAXN * MAXN];
int a[MAXN];
int s = 0;

void add(int x){
    s += x;
    for(int i = MAXN * MAXN - 1; i >= x; i--){
        dp[i] = dp[i] + dp[i - x];
        dp[i] %= MOD;
    }
}

void del(int x){
    s -= x;
    for(int i = x; i < MAXN * MAXN; i++){
        dp[i] = dp[i] - dp[i - x] + MOD;
        dp[i] %= MOD;
    }
}

void solve(){
    int n;
    cin >> n;

    for(int i = 0; i < n; i++){
        cin >> a[i];
    }

    dp[0] = 1;
    for(int i = 0; i < n; i++){
        add(a[i]);
    }

    if(s % 2 == 1){
        cout << "0\n";
        return;
    }

    if(dp[s / 2] == 0){
        cout << "0\n";
        return;
    }

    for(int i = 0; i < n; i++){
        del(a[i]);
        for(int j = 0; j <= s / 2; j++){
            if(dp[j]){
                f[s - 2 * j]++;
            }
        }
        add(a[i]);
    }

    vi res;
    for(int i = 0; i < MAXN * MAXN; i++){
        if(f[i] == n){
            res.pb(i);
        }
    }

    cout << sz(res) << '\n';
    for(auto ele : res){
        cout << ele << ' ';
    }
    cout << '\n';
}

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

    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1360 KB Output is correct
2 Correct 10 ms 1360 KB Output is correct
3 Correct 3 ms 1524 KB Output is correct
4 Correct 7 ms 1628 KB Output is correct
5 Correct 14 ms 1528 KB Output is correct
6 Correct 11 ms 1492 KB Output is correct
7 Correct 8 ms 1360 KB Output is correct
8 Correct 15 ms 1360 KB Output is correct
9 Correct 12 ms 1360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1360 KB Output is correct
2 Correct 10 ms 1360 KB Output is correct
3 Correct 3 ms 1524 KB Output is correct
4 Correct 7 ms 1628 KB Output is correct
5 Correct 14 ms 1528 KB Output is correct
6 Correct 11 ms 1492 KB Output is correct
7 Correct 8 ms 1360 KB Output is correct
8 Correct 15 ms 1360 KB Output is correct
9 Correct 12 ms 1360 KB Output is correct
10 Correct 39 ms 1360 KB Output is correct
11 Correct 39 ms 1528 KB Output is correct
12 Correct 39 ms 1360 KB Output is correct
13 Correct 33 ms 1532 KB Output is correct
14 Correct 34 ms 1528 KB Output is correct
15 Correct 38 ms 1528 KB Output is correct
16 Correct 40 ms 1360 KB Output is correct
17 Correct 24 ms 1492 KB Output is correct
18 Correct 35 ms 1484 KB Output is correct
19 Correct 33 ms 1360 KB Output is correct
20 Correct 33 ms 1360 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1360 KB Output is correct
2 Correct 10 ms 1360 KB Output is correct
3 Correct 3 ms 1524 KB Output is correct
4 Correct 7 ms 1628 KB Output is correct
5 Correct 14 ms 1528 KB Output is correct
6 Correct 11 ms 1492 KB Output is correct
7 Correct 8 ms 1360 KB Output is correct
8 Correct 15 ms 1360 KB Output is correct
9 Correct 12 ms 1360 KB Output is correct
10 Correct 39 ms 1360 KB Output is correct
11 Correct 39 ms 1528 KB Output is correct
12 Correct 39 ms 1360 KB Output is correct
13 Correct 33 ms 1532 KB Output is correct
14 Correct 34 ms 1528 KB Output is correct
15 Correct 38 ms 1528 KB Output is correct
16 Correct 40 ms 1360 KB Output is correct
17 Correct 24 ms 1492 KB Output is correct
18 Correct 35 ms 1484 KB Output is correct
19 Correct 33 ms 1360 KB Output is correct
20 Correct 33 ms 1360 KB Output is correct
21 Correct 73 ms 1492 KB Output is correct
22 Correct 81 ms 1528 KB Output is correct
23 Correct 56 ms 1528 KB Output is correct
24 Correct 101 ms 1508 KB Output is correct
25 Correct 104 ms 1500 KB Output is correct
26 Correct 104 ms 1480 KB Output is correct
27 Correct 119 ms 1500 KB Output is correct
28 Correct 104 ms 1484 KB Output is correct
29 Correct 111 ms 1480 KB Output is correct
30 Correct 114 ms 1488 KB Output is correct
31 Correct 105 ms 1360 KB Output is correct
32 Correct 124 ms 1480 KB Output is correct
33 Correct 104 ms 1528 KB Output is correct
34 Correct 104 ms 1484 KB Output is correct
35 Correct 110 ms 1484 KB Output is correct
36 Correct 109 ms 1528 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1360 KB Output is correct
2 Correct 10 ms 1360 KB Output is correct
3 Correct 3 ms 1524 KB Output is correct
4 Correct 7 ms 1628 KB Output is correct
5 Correct 14 ms 1528 KB Output is correct
6 Correct 11 ms 1492 KB Output is correct
7 Correct 8 ms 1360 KB Output is correct
8 Correct 15 ms 1360 KB Output is correct
9 Correct 12 ms 1360 KB Output is correct
10 Correct 39 ms 1360 KB Output is correct
11 Correct 39 ms 1528 KB Output is correct
12 Correct 39 ms 1360 KB Output is correct
13 Correct 33 ms 1532 KB Output is correct
14 Correct 34 ms 1528 KB Output is correct
15 Correct 38 ms 1528 KB Output is correct
16 Correct 40 ms 1360 KB Output is correct
17 Correct 24 ms 1492 KB Output is correct
18 Correct 35 ms 1484 KB Output is correct
19 Correct 33 ms 1360 KB Output is correct
20 Correct 33 ms 1360 KB Output is correct
21 Correct 73 ms 1492 KB Output is correct
22 Correct 81 ms 1528 KB Output is correct
23 Correct 56 ms 1528 KB Output is correct
24 Correct 101 ms 1508 KB Output is correct
25 Correct 104 ms 1500 KB Output is correct
26 Correct 104 ms 1480 KB Output is correct
27 Correct 119 ms 1500 KB Output is correct
28 Correct 104 ms 1484 KB Output is correct
29 Correct 111 ms 1480 KB Output is correct
30 Correct 114 ms 1488 KB Output is correct
31 Correct 105 ms 1360 KB Output is correct
32 Correct 124 ms 1480 KB Output is correct
33 Correct 104 ms 1528 KB Output is correct
34 Correct 104 ms 1484 KB Output is correct
35 Correct 110 ms 1484 KB Output is correct
36 Correct 109 ms 1528 KB Output is correct
37 Correct 207 ms 1608 KB Output is correct
38 Correct 208 ms 1488 KB Output is correct
39 Correct 268 ms 1488 KB Output is correct
40 Correct 296 ms 1740 KB Output is correct
41 Correct 323 ms 1608 KB Output is correct
42 Correct 282 ms 1744 KB Output is correct
43 Correct 257 ms 1996 KB Output is correct
44 Correct 270 ms 1868 KB Output is correct
45 Correct 267 ms 1864 KB Output is correct
46 Correct 293 ms 1476 KB Output is correct
47 Correct 272 ms 1604 KB Output is correct
48 Correct 262 ms 2000 KB Output is correct
49 Correct 288 ms 1724 KB Output is correct
50 Correct 266 ms 1740 KB Output is correct
51 Correct 86 ms 1360 KB Output is correct
52 Correct 285 ms 2000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1360 KB Output is correct
2 Correct 10 ms 1360 KB Output is correct
3 Correct 3 ms 1524 KB Output is correct
4 Correct 7 ms 1628 KB Output is correct
5 Correct 14 ms 1528 KB Output is correct
6 Correct 11 ms 1492 KB Output is correct
7 Correct 8 ms 1360 KB Output is correct
8 Correct 15 ms 1360 KB Output is correct
9 Correct 12 ms 1360 KB Output is correct
10 Correct 39 ms 1360 KB Output is correct
11 Correct 39 ms 1528 KB Output is correct
12 Correct 39 ms 1360 KB Output is correct
13 Correct 33 ms 1532 KB Output is correct
14 Correct 34 ms 1528 KB Output is correct
15 Correct 38 ms 1528 KB Output is correct
16 Correct 40 ms 1360 KB Output is correct
17 Correct 24 ms 1492 KB Output is correct
18 Correct 35 ms 1484 KB Output is correct
19 Correct 33 ms 1360 KB Output is correct
20 Correct 33 ms 1360 KB Output is correct
21 Correct 73 ms 1492 KB Output is correct
22 Correct 81 ms 1528 KB Output is correct
23 Correct 56 ms 1528 KB Output is correct
24 Correct 101 ms 1508 KB Output is correct
25 Correct 104 ms 1500 KB Output is correct
26 Correct 104 ms 1480 KB Output is correct
27 Correct 119 ms 1500 KB Output is correct
28 Correct 104 ms 1484 KB Output is correct
29 Correct 111 ms 1480 KB Output is correct
30 Correct 114 ms 1488 KB Output is correct
31 Correct 105 ms 1360 KB Output is correct
32 Correct 124 ms 1480 KB Output is correct
33 Correct 104 ms 1528 KB Output is correct
34 Correct 104 ms 1484 KB Output is correct
35 Correct 110 ms 1484 KB Output is correct
36 Correct 109 ms 1528 KB Output is correct
37 Correct 207 ms 1608 KB Output is correct
38 Correct 208 ms 1488 KB Output is correct
39 Correct 268 ms 1488 KB Output is correct
40 Correct 296 ms 1740 KB Output is correct
41 Correct 323 ms 1608 KB Output is correct
42 Correct 282 ms 1744 KB Output is correct
43 Correct 257 ms 1996 KB Output is correct
44 Correct 270 ms 1868 KB Output is correct
45 Correct 267 ms 1864 KB Output is correct
46 Correct 293 ms 1476 KB Output is correct
47 Correct 272 ms 1604 KB Output is correct
48 Correct 262 ms 2000 KB Output is correct
49 Correct 288 ms 1724 KB Output is correct
50 Correct 266 ms 1740 KB Output is correct
51 Correct 86 ms 1360 KB Output is correct
52 Correct 285 ms 2000 KB Output is correct
53 Correct 313 ms 1864 KB Output is correct
54 Correct 363 ms 1876 KB Output is correct
55 Correct 375 ms 2392 KB Output is correct
56 Correct 319 ms 1864 KB Output is correct
57 Correct 379 ms 2380 KB Output is correct
58 Correct 375 ms 2004 KB Output is correct
59 Correct 382 ms 2252 KB Output is correct
60 Correct 124 ms 1360 KB Output is correct
61 Correct 370 ms 2252 KB Output is correct
62 Correct 350 ms 2256 KB Output is correct
63 Correct 338 ms 2316 KB Output is correct
64 Correct 352 ms 2252 KB Output is correct
65 Correct 333 ms 1608 KB Output is correct
66 Correct 363 ms 1616 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 1360 KB Output is correct
2 Correct 10 ms 1360 KB Output is correct
3 Correct 3 ms 1524 KB Output is correct
4 Correct 7 ms 1628 KB Output is correct
5 Correct 14 ms 1528 KB Output is correct
6 Correct 11 ms 1492 KB Output is correct
7 Correct 8 ms 1360 KB Output is correct
8 Correct 15 ms 1360 KB Output is correct
9 Correct 12 ms 1360 KB Output is correct
10 Correct 39 ms 1360 KB Output is correct
11 Correct 39 ms 1528 KB Output is correct
12 Correct 39 ms 1360 KB Output is correct
13 Correct 33 ms 1532 KB Output is correct
14 Correct 34 ms 1528 KB Output is correct
15 Correct 38 ms 1528 KB Output is correct
16 Correct 40 ms 1360 KB Output is correct
17 Correct 24 ms 1492 KB Output is correct
18 Correct 35 ms 1484 KB Output is correct
19 Correct 33 ms 1360 KB Output is correct
20 Correct 33 ms 1360 KB Output is correct
21 Correct 73 ms 1492 KB Output is correct
22 Correct 81 ms 1528 KB Output is correct
23 Correct 56 ms 1528 KB Output is correct
24 Correct 101 ms 1508 KB Output is correct
25 Correct 104 ms 1500 KB Output is correct
26 Correct 104 ms 1480 KB Output is correct
27 Correct 119 ms 1500 KB Output is correct
28 Correct 104 ms 1484 KB Output is correct
29 Correct 111 ms 1480 KB Output is correct
30 Correct 114 ms 1488 KB Output is correct
31 Correct 105 ms 1360 KB Output is correct
32 Correct 124 ms 1480 KB Output is correct
33 Correct 104 ms 1528 KB Output is correct
34 Correct 104 ms 1484 KB Output is correct
35 Correct 110 ms 1484 KB Output is correct
36 Correct 109 ms 1528 KB Output is correct
37 Correct 207 ms 1608 KB Output is correct
38 Correct 208 ms 1488 KB Output is correct
39 Correct 268 ms 1488 KB Output is correct
40 Correct 296 ms 1740 KB Output is correct
41 Correct 323 ms 1608 KB Output is correct
42 Correct 282 ms 1744 KB Output is correct
43 Correct 257 ms 1996 KB Output is correct
44 Correct 270 ms 1868 KB Output is correct
45 Correct 267 ms 1864 KB Output is correct
46 Correct 293 ms 1476 KB Output is correct
47 Correct 272 ms 1604 KB Output is correct
48 Correct 262 ms 2000 KB Output is correct
49 Correct 288 ms 1724 KB Output is correct
50 Correct 266 ms 1740 KB Output is correct
51 Correct 86 ms 1360 KB Output is correct
52 Correct 285 ms 2000 KB Output is correct
53 Correct 313 ms 1864 KB Output is correct
54 Correct 363 ms 1876 KB Output is correct
55 Correct 375 ms 2392 KB Output is correct
56 Correct 319 ms 1864 KB Output is correct
57 Correct 379 ms 2380 KB Output is correct
58 Correct 375 ms 2004 KB Output is correct
59 Correct 382 ms 2252 KB Output is correct
60 Correct 124 ms 1360 KB Output is correct
61 Correct 370 ms 2252 KB Output is correct
62 Correct 350 ms 2256 KB Output is correct
63 Correct 338 ms 2316 KB Output is correct
64 Correct 352 ms 2252 KB Output is correct
65 Correct 333 ms 1608 KB Output is correct
66 Correct 363 ms 1616 KB Output is correct
67 Correct 439 ms 2180 KB Output is correct
68 Correct 184 ms 1484 KB Output is correct
69 Correct 576 ms 3272 KB Output is correct
70 Correct 590 ms 2632 KB Output is correct
71 Correct 554 ms 2612 KB Output is correct
72 Correct 576 ms 1744 KB Output is correct
73 Correct 545 ms 1864 KB Output is correct
74 Correct 556 ms 3528 KB Output is correct
75 Correct 538 ms 3016 KB Output is correct
76 Correct 565 ms 3600 KB Output is correct
77 Correct 575 ms 3564 KB Output is correct