답안 #962151

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962151 2024-04-13T07:51:15 Z Cookie Bootfall (IZhO17_bootfall) C++14
100 / 100
363 ms 3660 KB
#include<bits/stdc++.h>
#include<fstream>
using namespace std;
#define sz(a) (int)a.size()
#define ALL(v) v.begin(), v.end()
#define ALLR(v) v.rbegin(), v.rend()
#define ll long long
#define pb push_back
#define forr(i, a, b) for(int i = a; i < b; i++)
#define dorr(i, a, b) for(int i = a; i >= b; i--)
#define ld long double
#define vt vector
#include<fstream>
#define fi first
#define se second
#define pll pair<ll, ll>
#define pii pair<int, int>
#define mpp make_pair
const ld PI = 3.14159265359, prec = 1e-9;;
//using u128 = __uint128_t;
//const int x[4] = {1, 0, -1, 0};
//const int y[4] = {0, -1, 0, 1};
const ll mod = 1e9 + 7, pr = 31;
const int mxn = 3e5 + 5, mxq = 1e5 + 5, sq = 450, mxv = 5e4 + 1;
//const int base = (1 <<18);
const ll inf = 1e18 + 5, neg = -69420, inf2 = 1e14;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// have fun!
// <3;
int n;
int dp[505 * 505], a[505], cnt[505 * 505];
void add(int &a, int b){
    a += b;
    if(a >= mod)a -= mod;
}
void sub(int &a, int b){
    b = -b + mod;
    add(a, b);
}
void addv(int x){
    for(int j = 500 * 500; j >= x; j--){
       add(dp[j], dp[j - x]);
    }
}
void remv(int x){
    for(int j = x; j <= 500 * 500; j++){
       sub(dp[j], dp[j - x]);
    }
}
void solve(){
   cin >> n;
   int tot = 0;
   for(int i = 1; i <= n; i++){
       cin >> a[i]; tot += a[i];
   }
   dp[0] = 1;
   for(int i = 1; i <= n; i++){
       addv(a[i]);
   }
   if((tot & 1) ||  !dp[tot / 2]){
       cout << 0; return;
   }
   for(int i = 1; i <= n; i++){
       remv(a[i]);
       tot -= a[i];
       for(int j = 0; j <= tot / 2; j++){
           if(dp[j]){
               cnt[tot - 2 * j]++;
           }
       }
       addv(a[i]); 
       tot += a[i];
   }
  
   vt<int>res;
   for(int i = 1; i <= tot; i++){
       if(cnt[i] == n)res.pb(i);
   }
   cout << sz(res) << "\n";
   for(auto i: res)cout << i << " ";
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("netw.inp", "r", stdin);
    //freopen("netw.out", "w", stdout)
    int tt; tt = 1;
    while(tt--){
        solve();
 
    }
    return(0);
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1372 KB Output is correct
2 Correct 5 ms 1368 KB Output is correct
3 Correct 2 ms 1368 KB Output is correct
4 Correct 3 ms 1372 KB Output is correct
5 Correct 8 ms 1368 KB Output is correct
6 Correct 6 ms 1448 KB Output is correct
7 Correct 4 ms 1368 KB Output is correct
8 Correct 8 ms 1372 KB Output is correct
9 Correct 7 ms 1448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1372 KB Output is correct
2 Correct 5 ms 1368 KB Output is correct
3 Correct 2 ms 1368 KB Output is correct
4 Correct 3 ms 1372 KB Output is correct
5 Correct 8 ms 1368 KB Output is correct
6 Correct 6 ms 1448 KB Output is correct
7 Correct 4 ms 1368 KB Output is correct
8 Correct 8 ms 1372 KB Output is correct
9 Correct 7 ms 1448 KB Output is correct
10 Correct 25 ms 1368 KB Output is correct
11 Correct 23 ms 1368 KB Output is correct
12 Correct 24 ms 1372 KB Output is correct
13 Correct 18 ms 1372 KB Output is correct
14 Correct 19 ms 1452 KB Output is correct
15 Correct 21 ms 1448 KB Output is correct
16 Correct 23 ms 1372 KB Output is correct
17 Correct 13 ms 1452 KB Output is correct
18 Correct 16 ms 1372 KB Output is correct
19 Correct 22 ms 1372 KB Output is correct
20 Correct 19 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1372 KB Output is correct
2 Correct 5 ms 1368 KB Output is correct
3 Correct 2 ms 1368 KB Output is correct
4 Correct 3 ms 1372 KB Output is correct
5 Correct 8 ms 1368 KB Output is correct
6 Correct 6 ms 1448 KB Output is correct
7 Correct 4 ms 1368 KB Output is correct
8 Correct 8 ms 1372 KB Output is correct
9 Correct 7 ms 1448 KB Output is correct
10 Correct 25 ms 1368 KB Output is correct
11 Correct 23 ms 1368 KB Output is correct
12 Correct 24 ms 1372 KB Output is correct
13 Correct 18 ms 1372 KB Output is correct
14 Correct 19 ms 1452 KB Output is correct
15 Correct 21 ms 1448 KB Output is correct
16 Correct 23 ms 1372 KB Output is correct
17 Correct 13 ms 1452 KB Output is correct
18 Correct 16 ms 1372 KB Output is correct
19 Correct 22 ms 1372 KB Output is correct
20 Correct 19 ms 1372 KB Output is correct
21 Correct 41 ms 1452 KB Output is correct
22 Correct 47 ms 1444 KB Output is correct
23 Correct 43 ms 1368 KB Output is correct
24 Correct 61 ms 1452 KB Output is correct
25 Correct 65 ms 1460 KB Output is correct
26 Correct 63 ms 1652 KB Output is correct
27 Correct 62 ms 1528 KB Output is correct
28 Correct 63 ms 1372 KB Output is correct
29 Correct 62 ms 1468 KB Output is correct
30 Correct 62 ms 1372 KB Output is correct
31 Correct 71 ms 1444 KB Output is correct
32 Correct 63 ms 1456 KB Output is correct
33 Correct 63 ms 1372 KB Output is correct
34 Correct 69 ms 1460 KB Output is correct
35 Correct 74 ms 1464 KB Output is correct
36 Correct 65 ms 1428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1372 KB Output is correct
2 Correct 5 ms 1368 KB Output is correct
3 Correct 2 ms 1368 KB Output is correct
4 Correct 3 ms 1372 KB Output is correct
5 Correct 8 ms 1368 KB Output is correct
6 Correct 6 ms 1448 KB Output is correct
7 Correct 4 ms 1368 KB Output is correct
8 Correct 8 ms 1372 KB Output is correct
9 Correct 7 ms 1448 KB Output is correct
10 Correct 25 ms 1368 KB Output is correct
11 Correct 23 ms 1368 KB Output is correct
12 Correct 24 ms 1372 KB Output is correct
13 Correct 18 ms 1372 KB Output is correct
14 Correct 19 ms 1452 KB Output is correct
15 Correct 21 ms 1448 KB Output is correct
16 Correct 23 ms 1372 KB Output is correct
17 Correct 13 ms 1452 KB Output is correct
18 Correct 16 ms 1372 KB Output is correct
19 Correct 22 ms 1372 KB Output is correct
20 Correct 19 ms 1372 KB Output is correct
21 Correct 41 ms 1452 KB Output is correct
22 Correct 47 ms 1444 KB Output is correct
23 Correct 43 ms 1368 KB Output is correct
24 Correct 61 ms 1452 KB Output is correct
25 Correct 65 ms 1460 KB Output is correct
26 Correct 63 ms 1652 KB Output is correct
27 Correct 62 ms 1528 KB Output is correct
28 Correct 63 ms 1372 KB Output is correct
29 Correct 62 ms 1468 KB Output is correct
30 Correct 62 ms 1372 KB Output is correct
31 Correct 71 ms 1444 KB Output is correct
32 Correct 63 ms 1456 KB Output is correct
33 Correct 63 ms 1372 KB Output is correct
34 Correct 69 ms 1460 KB Output is correct
35 Correct 74 ms 1464 KB Output is correct
36 Correct 65 ms 1428 KB Output is correct
37 Correct 129 ms 1504 KB Output is correct
38 Correct 135 ms 1512 KB Output is correct
39 Correct 170 ms 1688 KB Output is correct
40 Correct 183 ms 1684 KB Output is correct
41 Correct 176 ms 1680 KB Output is correct
42 Correct 169 ms 1548 KB Output is correct
43 Correct 163 ms 1940 KB Output is correct
44 Correct 174 ms 1908 KB Output is correct
45 Correct 160 ms 1876 KB Output is correct
46 Correct 168 ms 1556 KB Output is correct
47 Correct 171 ms 1616 KB Output is correct
48 Correct 169 ms 1936 KB Output is correct
49 Correct 158 ms 1668 KB Output is correct
50 Correct 160 ms 1556 KB Output is correct
51 Correct 51 ms 1368 KB Output is correct
52 Correct 181 ms 2196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1372 KB Output is correct
2 Correct 5 ms 1368 KB Output is correct
3 Correct 2 ms 1368 KB Output is correct
4 Correct 3 ms 1372 KB Output is correct
5 Correct 8 ms 1368 KB Output is correct
6 Correct 6 ms 1448 KB Output is correct
7 Correct 4 ms 1368 KB Output is correct
8 Correct 8 ms 1372 KB Output is correct
9 Correct 7 ms 1448 KB Output is correct
10 Correct 25 ms 1368 KB Output is correct
11 Correct 23 ms 1368 KB Output is correct
12 Correct 24 ms 1372 KB Output is correct
13 Correct 18 ms 1372 KB Output is correct
14 Correct 19 ms 1452 KB Output is correct
15 Correct 21 ms 1448 KB Output is correct
16 Correct 23 ms 1372 KB Output is correct
17 Correct 13 ms 1452 KB Output is correct
18 Correct 16 ms 1372 KB Output is correct
19 Correct 22 ms 1372 KB Output is correct
20 Correct 19 ms 1372 KB Output is correct
21 Correct 41 ms 1452 KB Output is correct
22 Correct 47 ms 1444 KB Output is correct
23 Correct 43 ms 1368 KB Output is correct
24 Correct 61 ms 1452 KB Output is correct
25 Correct 65 ms 1460 KB Output is correct
26 Correct 63 ms 1652 KB Output is correct
27 Correct 62 ms 1528 KB Output is correct
28 Correct 63 ms 1372 KB Output is correct
29 Correct 62 ms 1468 KB Output is correct
30 Correct 62 ms 1372 KB Output is correct
31 Correct 71 ms 1444 KB Output is correct
32 Correct 63 ms 1456 KB Output is correct
33 Correct 63 ms 1372 KB Output is correct
34 Correct 69 ms 1460 KB Output is correct
35 Correct 74 ms 1464 KB Output is correct
36 Correct 65 ms 1428 KB Output is correct
37 Correct 129 ms 1504 KB Output is correct
38 Correct 135 ms 1512 KB Output is correct
39 Correct 170 ms 1688 KB Output is correct
40 Correct 183 ms 1684 KB Output is correct
41 Correct 176 ms 1680 KB Output is correct
42 Correct 169 ms 1548 KB Output is correct
43 Correct 163 ms 1940 KB Output is correct
44 Correct 174 ms 1908 KB Output is correct
45 Correct 160 ms 1876 KB Output is correct
46 Correct 168 ms 1556 KB Output is correct
47 Correct 171 ms 1616 KB Output is correct
48 Correct 169 ms 1936 KB Output is correct
49 Correct 158 ms 1668 KB Output is correct
50 Correct 160 ms 1556 KB Output is correct
51 Correct 51 ms 1368 KB Output is correct
52 Correct 181 ms 2196 KB Output is correct
53 Correct 199 ms 1856 KB Output is correct
54 Correct 221 ms 1892 KB Output is correct
55 Correct 260 ms 2248 KB Output is correct
56 Correct 194 ms 1872 KB Output is correct
57 Correct 237 ms 2528 KB Output is correct
58 Correct 227 ms 1960 KB Output is correct
59 Correct 225 ms 2112 KB Output is correct
60 Correct 70 ms 1368 KB Output is correct
61 Correct 232 ms 2260 KB Output is correct
62 Correct 211 ms 2340 KB Output is correct
63 Correct 234 ms 2220 KB Output is correct
64 Correct 204 ms 2304 KB Output is correct
65 Correct 200 ms 1612 KB Output is correct
66 Correct 204 ms 1636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 1372 KB Output is correct
2 Correct 5 ms 1368 KB Output is correct
3 Correct 2 ms 1368 KB Output is correct
4 Correct 3 ms 1372 KB Output is correct
5 Correct 8 ms 1368 KB Output is correct
6 Correct 6 ms 1448 KB Output is correct
7 Correct 4 ms 1368 KB Output is correct
8 Correct 8 ms 1372 KB Output is correct
9 Correct 7 ms 1448 KB Output is correct
10 Correct 25 ms 1368 KB Output is correct
11 Correct 23 ms 1368 KB Output is correct
12 Correct 24 ms 1372 KB Output is correct
13 Correct 18 ms 1372 KB Output is correct
14 Correct 19 ms 1452 KB Output is correct
15 Correct 21 ms 1448 KB Output is correct
16 Correct 23 ms 1372 KB Output is correct
17 Correct 13 ms 1452 KB Output is correct
18 Correct 16 ms 1372 KB Output is correct
19 Correct 22 ms 1372 KB Output is correct
20 Correct 19 ms 1372 KB Output is correct
21 Correct 41 ms 1452 KB Output is correct
22 Correct 47 ms 1444 KB Output is correct
23 Correct 43 ms 1368 KB Output is correct
24 Correct 61 ms 1452 KB Output is correct
25 Correct 65 ms 1460 KB Output is correct
26 Correct 63 ms 1652 KB Output is correct
27 Correct 62 ms 1528 KB Output is correct
28 Correct 63 ms 1372 KB Output is correct
29 Correct 62 ms 1468 KB Output is correct
30 Correct 62 ms 1372 KB Output is correct
31 Correct 71 ms 1444 KB Output is correct
32 Correct 63 ms 1456 KB Output is correct
33 Correct 63 ms 1372 KB Output is correct
34 Correct 69 ms 1460 KB Output is correct
35 Correct 74 ms 1464 KB Output is correct
36 Correct 65 ms 1428 KB Output is correct
37 Correct 129 ms 1504 KB Output is correct
38 Correct 135 ms 1512 KB Output is correct
39 Correct 170 ms 1688 KB Output is correct
40 Correct 183 ms 1684 KB Output is correct
41 Correct 176 ms 1680 KB Output is correct
42 Correct 169 ms 1548 KB Output is correct
43 Correct 163 ms 1940 KB Output is correct
44 Correct 174 ms 1908 KB Output is correct
45 Correct 160 ms 1876 KB Output is correct
46 Correct 168 ms 1556 KB Output is correct
47 Correct 171 ms 1616 KB Output is correct
48 Correct 169 ms 1936 KB Output is correct
49 Correct 158 ms 1668 KB Output is correct
50 Correct 160 ms 1556 KB Output is correct
51 Correct 51 ms 1368 KB Output is correct
52 Correct 181 ms 2196 KB Output is correct
53 Correct 199 ms 1856 KB Output is correct
54 Correct 221 ms 1892 KB Output is correct
55 Correct 260 ms 2248 KB Output is correct
56 Correct 194 ms 1872 KB Output is correct
57 Correct 237 ms 2528 KB Output is correct
58 Correct 227 ms 1960 KB Output is correct
59 Correct 225 ms 2112 KB Output is correct
60 Correct 70 ms 1368 KB Output is correct
61 Correct 232 ms 2260 KB Output is correct
62 Correct 211 ms 2340 KB Output is correct
63 Correct 234 ms 2220 KB Output is correct
64 Correct 204 ms 2304 KB Output is correct
65 Correct 200 ms 1612 KB Output is correct
66 Correct 204 ms 1636 KB Output is correct
67 Correct 258 ms 2264 KB Output is correct
68 Correct 101 ms 1372 KB Output is correct
69 Correct 358 ms 3348 KB Output is correct
70 Correct 356 ms 2576 KB Output is correct
71 Correct 335 ms 2588 KB Output is correct
72 Correct 326 ms 1692 KB Output is correct
73 Correct 340 ms 1912 KB Output is correct
74 Correct 359 ms 3452 KB Output is correct
75 Correct 352 ms 3088 KB Output is correct
76 Correct 350 ms 3348 KB Output is correct
77 Correct 363 ms 3660 KB Output is correct