답안 #962150

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
962150 2024-04-13T07:50:44 Z Cookie Bootfall (IZhO17_bootfall) C++14
44 / 100
247 ms 2520 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 = 998244353, 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 5 ms 1372 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 4 ms 1372 KB Output is correct
5 Correct 8 ms 1456 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 5 ms 1372 KB Output is correct
8 Correct 9 ms 1456 KB Output is correct
9 Correct 7 ms 1372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 4 ms 1372 KB Output is correct
5 Correct 8 ms 1456 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 5 ms 1372 KB Output is correct
8 Correct 9 ms 1456 KB Output is correct
9 Correct 7 ms 1372 KB Output is correct
10 Correct 21 ms 1452 KB Output is correct
11 Correct 31 ms 1372 KB Output is correct
12 Correct 23 ms 1372 KB Output is correct
13 Correct 18 ms 1448 KB Output is correct
14 Correct 22 ms 1368 KB Output is correct
15 Correct 21 ms 1372 KB Output is correct
16 Correct 24 ms 1372 KB Output is correct
17 Correct 13 ms 1448 KB Output is correct
18 Correct 17 ms 1236 KB Output is correct
19 Correct 19 ms 1372 KB Output is correct
20 Correct 22 ms 1452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 4 ms 1372 KB Output is correct
5 Correct 8 ms 1456 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 5 ms 1372 KB Output is correct
8 Correct 9 ms 1456 KB Output is correct
9 Correct 7 ms 1372 KB Output is correct
10 Correct 21 ms 1452 KB Output is correct
11 Correct 31 ms 1372 KB Output is correct
12 Correct 23 ms 1372 KB Output is correct
13 Correct 18 ms 1448 KB Output is correct
14 Correct 22 ms 1368 KB Output is correct
15 Correct 21 ms 1372 KB Output is correct
16 Correct 24 ms 1372 KB Output is correct
17 Correct 13 ms 1448 KB Output is correct
18 Correct 17 ms 1236 KB Output is correct
19 Correct 19 ms 1372 KB Output is correct
20 Correct 22 ms 1452 KB Output is correct
21 Correct 45 ms 1444 KB Output is correct
22 Correct 49 ms 1452 KB Output is correct
23 Correct 33 ms 1372 KB Output is correct
24 Correct 64 ms 1444 KB Output is correct
25 Correct 77 ms 1624 KB Output is correct
26 Correct 62 ms 1460 KB Output is correct
27 Correct 67 ms 1456 KB Output is correct
28 Correct 64 ms 1464 KB Output is correct
29 Correct 65 ms 1464 KB Output is correct
30 Correct 70 ms 1372 KB Output is correct
31 Correct 63 ms 1448 KB Output is correct
32 Correct 82 ms 1440 KB Output is correct
33 Correct 65 ms 1368 KB Output is correct
34 Correct 67 ms 1460 KB Output is correct
35 Correct 64 ms 1340 KB Output is correct
36 Correct 67 ms 1452 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 4 ms 1372 KB Output is correct
5 Correct 8 ms 1456 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 5 ms 1372 KB Output is correct
8 Correct 9 ms 1456 KB Output is correct
9 Correct 7 ms 1372 KB Output is correct
10 Correct 21 ms 1452 KB Output is correct
11 Correct 31 ms 1372 KB Output is correct
12 Correct 23 ms 1372 KB Output is correct
13 Correct 18 ms 1448 KB Output is correct
14 Correct 22 ms 1368 KB Output is correct
15 Correct 21 ms 1372 KB Output is correct
16 Correct 24 ms 1372 KB Output is correct
17 Correct 13 ms 1448 KB Output is correct
18 Correct 17 ms 1236 KB Output is correct
19 Correct 19 ms 1372 KB Output is correct
20 Correct 22 ms 1452 KB Output is correct
21 Correct 45 ms 1444 KB Output is correct
22 Correct 49 ms 1452 KB Output is correct
23 Correct 33 ms 1372 KB Output is correct
24 Correct 64 ms 1444 KB Output is correct
25 Correct 77 ms 1624 KB Output is correct
26 Correct 62 ms 1460 KB Output is correct
27 Correct 67 ms 1456 KB Output is correct
28 Correct 64 ms 1464 KB Output is correct
29 Correct 65 ms 1464 KB Output is correct
30 Correct 70 ms 1372 KB Output is correct
31 Correct 63 ms 1448 KB Output is correct
32 Correct 82 ms 1440 KB Output is correct
33 Correct 65 ms 1368 KB Output is correct
34 Correct 67 ms 1460 KB Output is correct
35 Correct 64 ms 1340 KB Output is correct
36 Correct 67 ms 1452 KB Output is correct
37 Correct 130 ms 1500 KB Output is correct
38 Correct 134 ms 1444 KB Output is correct
39 Correct 181 ms 1424 KB Output is correct
40 Correct 171 ms 1700 KB Output is correct
41 Correct 189 ms 1696 KB Output is correct
42 Correct 165 ms 1540 KB Output is correct
43 Correct 179 ms 1876 KB Output is correct
44 Correct 170 ms 1900 KB Output is correct
45 Correct 185 ms 1900 KB Output is correct
46 Correct 172 ms 1552 KB Output is correct
47 Correct 174 ms 1552 KB Output is correct
48 Correct 172 ms 1884 KB Output is correct
49 Correct 161 ms 1684 KB Output is correct
50 Correct 161 ms 1556 KB Output is correct
51 Correct 52 ms 1424 KB Output is correct
52 Correct 173 ms 1876 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 4 ms 1372 KB Output is correct
5 Correct 8 ms 1456 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 5 ms 1372 KB Output is correct
8 Correct 9 ms 1456 KB Output is correct
9 Correct 7 ms 1372 KB Output is correct
10 Correct 21 ms 1452 KB Output is correct
11 Correct 31 ms 1372 KB Output is correct
12 Correct 23 ms 1372 KB Output is correct
13 Correct 18 ms 1448 KB Output is correct
14 Correct 22 ms 1368 KB Output is correct
15 Correct 21 ms 1372 KB Output is correct
16 Correct 24 ms 1372 KB Output is correct
17 Correct 13 ms 1448 KB Output is correct
18 Correct 17 ms 1236 KB Output is correct
19 Correct 19 ms 1372 KB Output is correct
20 Correct 22 ms 1452 KB Output is correct
21 Correct 45 ms 1444 KB Output is correct
22 Correct 49 ms 1452 KB Output is correct
23 Correct 33 ms 1372 KB Output is correct
24 Correct 64 ms 1444 KB Output is correct
25 Correct 77 ms 1624 KB Output is correct
26 Correct 62 ms 1460 KB Output is correct
27 Correct 67 ms 1456 KB Output is correct
28 Correct 64 ms 1464 KB Output is correct
29 Correct 65 ms 1464 KB Output is correct
30 Correct 70 ms 1372 KB Output is correct
31 Correct 63 ms 1448 KB Output is correct
32 Correct 82 ms 1440 KB Output is correct
33 Correct 65 ms 1368 KB Output is correct
34 Correct 67 ms 1460 KB Output is correct
35 Correct 64 ms 1340 KB Output is correct
36 Correct 67 ms 1452 KB Output is correct
37 Correct 130 ms 1500 KB Output is correct
38 Correct 134 ms 1444 KB Output is correct
39 Correct 181 ms 1424 KB Output is correct
40 Correct 171 ms 1700 KB Output is correct
41 Correct 189 ms 1696 KB Output is correct
42 Correct 165 ms 1540 KB Output is correct
43 Correct 179 ms 1876 KB Output is correct
44 Correct 170 ms 1900 KB Output is correct
45 Correct 185 ms 1900 KB Output is correct
46 Correct 172 ms 1552 KB Output is correct
47 Correct 174 ms 1552 KB Output is correct
48 Correct 172 ms 1884 KB Output is correct
49 Correct 161 ms 1684 KB Output is correct
50 Correct 161 ms 1556 KB Output is correct
51 Correct 52 ms 1424 KB Output is correct
52 Correct 173 ms 1876 KB Output is correct
53 Correct 193 ms 1868 KB Output is correct
54 Correct 231 ms 1876 KB Output is correct
55 Correct 231 ms 2328 KB Output is correct
56 Correct 196 ms 1896 KB Output is correct
57 Correct 247 ms 2520 KB Output is correct
58 Incorrect 238 ms 1876 KB Output isn't correct
59 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 1372 KB Output is correct
2 Correct 5 ms 1236 KB Output is correct
3 Correct 2 ms 1372 KB Output is correct
4 Correct 4 ms 1372 KB Output is correct
5 Correct 8 ms 1456 KB Output is correct
6 Correct 6 ms 1372 KB Output is correct
7 Correct 5 ms 1372 KB Output is correct
8 Correct 9 ms 1456 KB Output is correct
9 Correct 7 ms 1372 KB Output is correct
10 Correct 21 ms 1452 KB Output is correct
11 Correct 31 ms 1372 KB Output is correct
12 Correct 23 ms 1372 KB Output is correct
13 Correct 18 ms 1448 KB Output is correct
14 Correct 22 ms 1368 KB Output is correct
15 Correct 21 ms 1372 KB Output is correct
16 Correct 24 ms 1372 KB Output is correct
17 Correct 13 ms 1448 KB Output is correct
18 Correct 17 ms 1236 KB Output is correct
19 Correct 19 ms 1372 KB Output is correct
20 Correct 22 ms 1452 KB Output is correct
21 Correct 45 ms 1444 KB Output is correct
22 Correct 49 ms 1452 KB Output is correct
23 Correct 33 ms 1372 KB Output is correct
24 Correct 64 ms 1444 KB Output is correct
25 Correct 77 ms 1624 KB Output is correct
26 Correct 62 ms 1460 KB Output is correct
27 Correct 67 ms 1456 KB Output is correct
28 Correct 64 ms 1464 KB Output is correct
29 Correct 65 ms 1464 KB Output is correct
30 Correct 70 ms 1372 KB Output is correct
31 Correct 63 ms 1448 KB Output is correct
32 Correct 82 ms 1440 KB Output is correct
33 Correct 65 ms 1368 KB Output is correct
34 Correct 67 ms 1460 KB Output is correct
35 Correct 64 ms 1340 KB Output is correct
36 Correct 67 ms 1452 KB Output is correct
37 Correct 130 ms 1500 KB Output is correct
38 Correct 134 ms 1444 KB Output is correct
39 Correct 181 ms 1424 KB Output is correct
40 Correct 171 ms 1700 KB Output is correct
41 Correct 189 ms 1696 KB Output is correct
42 Correct 165 ms 1540 KB Output is correct
43 Correct 179 ms 1876 KB Output is correct
44 Correct 170 ms 1900 KB Output is correct
45 Correct 185 ms 1900 KB Output is correct
46 Correct 172 ms 1552 KB Output is correct
47 Correct 174 ms 1552 KB Output is correct
48 Correct 172 ms 1884 KB Output is correct
49 Correct 161 ms 1684 KB Output is correct
50 Correct 161 ms 1556 KB Output is correct
51 Correct 52 ms 1424 KB Output is correct
52 Correct 173 ms 1876 KB Output is correct
53 Correct 193 ms 1868 KB Output is correct
54 Correct 231 ms 1876 KB Output is correct
55 Correct 231 ms 2328 KB Output is correct
56 Correct 196 ms 1896 KB Output is correct
57 Correct 247 ms 2520 KB Output is correct
58 Incorrect 238 ms 1876 KB Output isn't correct
59 Halted 0 ms 0 KB -