답안 #306474

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
306474 2020-09-25T16:28:03 Z VROOM_VARUN Bootfall (IZhO17_bootfall) C++14
100 / 100
641 ms 4172 KB
/*
ID: varunra2
LANG: C++
TASK: bootfall
*/

#include<bits/stdc++.h>
using namespace std;

#ifdef DEBUG
#include "lib/debug.h"
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define debug_arr(...) \
  cerr << "[" << #__VA_ARGS__ << "]:", debug_arr(__VA_ARGS__)
#pragma GCC diagnostic ignored "-Wsign-compare"
//#pragma GCC diagnostic ignored "-Wunused-parameter"
//#pragma GCC diagnostic ignored "-Wunused-variable"
#else
#define debug(...) 42
#endif

#define EPS 1e-9
#define IN(A, B, C) assert(B <= A && A <= C)
#define INF (int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))
#define MOD 1000000007
#define MP make_pair
#define PB push_back
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define x first
#define y second

const double PI = acos(-1.0);
typedef long long ll;
typedef long double ld;
typedef pair<int, int> PII;
typedef map<int, int> MPII;
typedef multiset<int> MSETI;
typedef set<int> SETI;
typedef set<string> SETS;
typedef vector<int> VI;
typedef vector<PII> VII;
typedef vector<VI> VVI;
typedef vector<string> VS;

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define sz(x) (int)(x).size()
typedef pair<int, int> pii;
typedef vector<int> vi;
#pragma GCC diagnostic ignored "-Wsign-compare"
// util functions

#define N 502
#define siz N * N + 1

int n;

int main() {
// #ifndef ONLINE_JUDGE
  // freopen("bootfall.in", "r", stdin);
  // freopen("bootfall.out", "w", stdout);
// #endif
  cin.sync_with_stdio(0); cin.tie(0);

  cin >> n;

  VI vals(n);

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

  int sm = accumulate(all(vals), 0);

  VI cur(siz, 0), prv(siz, 0);

  cur[0] = prv[0] = 1;

  for(int i = 0; i < n; i++) {
    for(int j = vals[i]; j < siz; j++) {
      cur[j] += prv[j - vals[i]];
    }
    prv = cur;
  }

  bitset<siz> ret;
  bitset<siz> each;

  if(sm&1 or cur[sm/2] == 0) {
    cout << "0\n";
    return 0;
  }


  VI a;
  ret.set();
  for(int i = 0; i < n; i++) {
    sm -= vals[i];
    a = cur;
    each.reset();
    // undo
    for(int ii = vals[i]; ii < siz; ii++) {
      if(a[ii]) a[ii] -= a[ii - vals[i]]; 
    }
    for(int ii = 0; ii <= sm; ii++) {
      if(a[ii]) {
        int l, r;
        l = ii;
        r = sm - l;
        each[abs(r - l)] = 1;
      }
    }
    ret &= each;
    sm += vals[i];
  }

  cout << ret.count() << '\n';

  for(int i = 0; i < siz; i++) {
    if(ret[i]) cout << i << " ";
  }
  cout << '\n';

  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3328 KB Output is correct
2 Correct 7 ms 3328 KB Output is correct
3 Correct 3 ms 2432 KB Output is correct
4 Correct 6 ms 3408 KB Output is correct
5 Correct 10 ms 3328 KB Output is correct
6 Correct 8 ms 3328 KB Output is correct
7 Correct 7 ms 3328 KB Output is correct
8 Correct 11 ms 3328 KB Output is correct
9 Correct 10 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3328 KB Output is correct
2 Correct 7 ms 3328 KB Output is correct
3 Correct 3 ms 2432 KB Output is correct
4 Correct 6 ms 3408 KB Output is correct
5 Correct 10 ms 3328 KB Output is correct
6 Correct 8 ms 3328 KB Output is correct
7 Correct 7 ms 3328 KB Output is correct
8 Correct 11 ms 3328 KB Output is correct
9 Correct 10 ms 3328 KB Output is correct
10 Correct 22 ms 3584 KB Output is correct
11 Correct 22 ms 3328 KB Output is correct
12 Correct 22 ms 3328 KB Output is correct
13 Correct 20 ms 3456 KB Output is correct
14 Correct 21 ms 3328 KB Output is correct
15 Correct 21 ms 3320 KB Output is correct
16 Correct 22 ms 3328 KB Output is correct
17 Correct 16 ms 3328 KB Output is correct
18 Correct 21 ms 3532 KB Output is correct
19 Correct 20 ms 3328 KB Output is correct
20 Correct 23 ms 3328 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3328 KB Output is correct
2 Correct 7 ms 3328 KB Output is correct
3 Correct 3 ms 2432 KB Output is correct
4 Correct 6 ms 3408 KB Output is correct
5 Correct 10 ms 3328 KB Output is correct
6 Correct 8 ms 3328 KB Output is correct
7 Correct 7 ms 3328 KB Output is correct
8 Correct 11 ms 3328 KB Output is correct
9 Correct 10 ms 3328 KB Output is correct
10 Correct 22 ms 3584 KB Output is correct
11 Correct 22 ms 3328 KB Output is correct
12 Correct 22 ms 3328 KB Output is correct
13 Correct 20 ms 3456 KB Output is correct
14 Correct 21 ms 3328 KB Output is correct
15 Correct 21 ms 3320 KB Output is correct
16 Correct 22 ms 3328 KB Output is correct
17 Correct 16 ms 3328 KB Output is correct
18 Correct 21 ms 3532 KB Output is correct
19 Correct 20 ms 3328 KB Output is correct
20 Correct 23 ms 3328 KB Output is correct
21 Correct 44 ms 3328 KB Output is correct
22 Correct 52 ms 3320 KB Output is correct
23 Correct 35 ms 3456 KB Output is correct
24 Correct 63 ms 3320 KB Output is correct
25 Correct 64 ms 3328 KB Output is correct
26 Correct 70 ms 3320 KB Output is correct
27 Correct 68 ms 3320 KB Output is correct
28 Correct 67 ms 3448 KB Output is correct
29 Correct 68 ms 3320 KB Output is correct
30 Correct 69 ms 3320 KB Output is correct
31 Correct 67 ms 3324 KB Output is correct
32 Correct 69 ms 3320 KB Output is correct
33 Correct 68 ms 3448 KB Output is correct
34 Correct 69 ms 3448 KB Output is correct
35 Correct 79 ms 3320 KB Output is correct
36 Correct 69 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3328 KB Output is correct
2 Correct 7 ms 3328 KB Output is correct
3 Correct 3 ms 2432 KB Output is correct
4 Correct 6 ms 3408 KB Output is correct
5 Correct 10 ms 3328 KB Output is correct
6 Correct 8 ms 3328 KB Output is correct
7 Correct 7 ms 3328 KB Output is correct
8 Correct 11 ms 3328 KB Output is correct
9 Correct 10 ms 3328 KB Output is correct
10 Correct 22 ms 3584 KB Output is correct
11 Correct 22 ms 3328 KB Output is correct
12 Correct 22 ms 3328 KB Output is correct
13 Correct 20 ms 3456 KB Output is correct
14 Correct 21 ms 3328 KB Output is correct
15 Correct 21 ms 3320 KB Output is correct
16 Correct 22 ms 3328 KB Output is correct
17 Correct 16 ms 3328 KB Output is correct
18 Correct 21 ms 3532 KB Output is correct
19 Correct 20 ms 3328 KB Output is correct
20 Correct 23 ms 3328 KB Output is correct
21 Correct 44 ms 3328 KB Output is correct
22 Correct 52 ms 3320 KB Output is correct
23 Correct 35 ms 3456 KB Output is correct
24 Correct 63 ms 3320 KB Output is correct
25 Correct 64 ms 3328 KB Output is correct
26 Correct 70 ms 3320 KB Output is correct
27 Correct 68 ms 3320 KB Output is correct
28 Correct 67 ms 3448 KB Output is correct
29 Correct 68 ms 3320 KB Output is correct
30 Correct 69 ms 3320 KB Output is correct
31 Correct 67 ms 3324 KB Output is correct
32 Correct 69 ms 3320 KB Output is correct
33 Correct 68 ms 3448 KB Output is correct
34 Correct 69 ms 3448 KB Output is correct
35 Correct 79 ms 3320 KB Output is correct
36 Correct 69 ms 3448 KB Output is correct
37 Correct 145 ms 3448 KB Output is correct
38 Correct 142 ms 3448 KB Output is correct
39 Correct 182 ms 3320 KB Output is correct
40 Correct 201 ms 3448 KB Output is correct
41 Correct 194 ms 3320 KB Output is correct
42 Correct 182 ms 3448 KB Output is correct
43 Correct 229 ms 3532 KB Output is correct
44 Correct 196 ms 3448 KB Output is correct
45 Correct 199 ms 3576 KB Output is correct
46 Correct 197 ms 3320 KB Output is correct
47 Correct 201 ms 3448 KB Output is correct
48 Correct 199 ms 3528 KB Output is correct
49 Correct 191 ms 3400 KB Output is correct
50 Correct 196 ms 3424 KB Output is correct
51 Correct 87 ms 2352 KB Output is correct
52 Correct 222 ms 3576 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3328 KB Output is correct
2 Correct 7 ms 3328 KB Output is correct
3 Correct 3 ms 2432 KB Output is correct
4 Correct 6 ms 3408 KB Output is correct
5 Correct 10 ms 3328 KB Output is correct
6 Correct 8 ms 3328 KB Output is correct
7 Correct 7 ms 3328 KB Output is correct
8 Correct 11 ms 3328 KB Output is correct
9 Correct 10 ms 3328 KB Output is correct
10 Correct 22 ms 3584 KB Output is correct
11 Correct 22 ms 3328 KB Output is correct
12 Correct 22 ms 3328 KB Output is correct
13 Correct 20 ms 3456 KB Output is correct
14 Correct 21 ms 3328 KB Output is correct
15 Correct 21 ms 3320 KB Output is correct
16 Correct 22 ms 3328 KB Output is correct
17 Correct 16 ms 3328 KB Output is correct
18 Correct 21 ms 3532 KB Output is correct
19 Correct 20 ms 3328 KB Output is correct
20 Correct 23 ms 3328 KB Output is correct
21 Correct 44 ms 3328 KB Output is correct
22 Correct 52 ms 3320 KB Output is correct
23 Correct 35 ms 3456 KB Output is correct
24 Correct 63 ms 3320 KB Output is correct
25 Correct 64 ms 3328 KB Output is correct
26 Correct 70 ms 3320 KB Output is correct
27 Correct 68 ms 3320 KB Output is correct
28 Correct 67 ms 3448 KB Output is correct
29 Correct 68 ms 3320 KB Output is correct
30 Correct 69 ms 3320 KB Output is correct
31 Correct 67 ms 3324 KB Output is correct
32 Correct 69 ms 3320 KB Output is correct
33 Correct 68 ms 3448 KB Output is correct
34 Correct 69 ms 3448 KB Output is correct
35 Correct 79 ms 3320 KB Output is correct
36 Correct 69 ms 3448 KB Output is correct
37 Correct 145 ms 3448 KB Output is correct
38 Correct 142 ms 3448 KB Output is correct
39 Correct 182 ms 3320 KB Output is correct
40 Correct 201 ms 3448 KB Output is correct
41 Correct 194 ms 3320 KB Output is correct
42 Correct 182 ms 3448 KB Output is correct
43 Correct 229 ms 3532 KB Output is correct
44 Correct 196 ms 3448 KB Output is correct
45 Correct 199 ms 3576 KB Output is correct
46 Correct 197 ms 3320 KB Output is correct
47 Correct 201 ms 3448 KB Output is correct
48 Correct 199 ms 3528 KB Output is correct
49 Correct 191 ms 3400 KB Output is correct
50 Correct 196 ms 3424 KB Output is correct
51 Correct 87 ms 2352 KB Output is correct
52 Correct 222 ms 3576 KB Output is correct
53 Correct 267 ms 3664 KB Output is correct
54 Correct 276 ms 3576 KB Output is correct
55 Correct 356 ms 3704 KB Output is correct
56 Correct 243 ms 3576 KB Output is correct
57 Correct 345 ms 3664 KB Output is correct
58 Correct 285 ms 3576 KB Output is correct
59 Correct 304 ms 3576 KB Output is correct
60 Correct 110 ms 2424 KB Output is correct
61 Correct 303 ms 3720 KB Output is correct
62 Correct 298 ms 3704 KB Output is correct
63 Correct 294 ms 3704 KB Output is correct
64 Correct 286 ms 3668 KB Output is correct
65 Correct 243 ms 3320 KB Output is correct
66 Correct 219 ms 3448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 3328 KB Output is correct
2 Correct 7 ms 3328 KB Output is correct
3 Correct 3 ms 2432 KB Output is correct
4 Correct 6 ms 3408 KB Output is correct
5 Correct 10 ms 3328 KB Output is correct
6 Correct 8 ms 3328 KB Output is correct
7 Correct 7 ms 3328 KB Output is correct
8 Correct 11 ms 3328 KB Output is correct
9 Correct 10 ms 3328 KB Output is correct
10 Correct 22 ms 3584 KB Output is correct
11 Correct 22 ms 3328 KB Output is correct
12 Correct 22 ms 3328 KB Output is correct
13 Correct 20 ms 3456 KB Output is correct
14 Correct 21 ms 3328 KB Output is correct
15 Correct 21 ms 3320 KB Output is correct
16 Correct 22 ms 3328 KB Output is correct
17 Correct 16 ms 3328 KB Output is correct
18 Correct 21 ms 3532 KB Output is correct
19 Correct 20 ms 3328 KB Output is correct
20 Correct 23 ms 3328 KB Output is correct
21 Correct 44 ms 3328 KB Output is correct
22 Correct 52 ms 3320 KB Output is correct
23 Correct 35 ms 3456 KB Output is correct
24 Correct 63 ms 3320 KB Output is correct
25 Correct 64 ms 3328 KB Output is correct
26 Correct 70 ms 3320 KB Output is correct
27 Correct 68 ms 3320 KB Output is correct
28 Correct 67 ms 3448 KB Output is correct
29 Correct 68 ms 3320 KB Output is correct
30 Correct 69 ms 3320 KB Output is correct
31 Correct 67 ms 3324 KB Output is correct
32 Correct 69 ms 3320 KB Output is correct
33 Correct 68 ms 3448 KB Output is correct
34 Correct 69 ms 3448 KB Output is correct
35 Correct 79 ms 3320 KB Output is correct
36 Correct 69 ms 3448 KB Output is correct
37 Correct 145 ms 3448 KB Output is correct
38 Correct 142 ms 3448 KB Output is correct
39 Correct 182 ms 3320 KB Output is correct
40 Correct 201 ms 3448 KB Output is correct
41 Correct 194 ms 3320 KB Output is correct
42 Correct 182 ms 3448 KB Output is correct
43 Correct 229 ms 3532 KB Output is correct
44 Correct 196 ms 3448 KB Output is correct
45 Correct 199 ms 3576 KB Output is correct
46 Correct 197 ms 3320 KB Output is correct
47 Correct 201 ms 3448 KB Output is correct
48 Correct 199 ms 3528 KB Output is correct
49 Correct 191 ms 3400 KB Output is correct
50 Correct 196 ms 3424 KB Output is correct
51 Correct 87 ms 2352 KB Output is correct
52 Correct 222 ms 3576 KB Output is correct
53 Correct 267 ms 3664 KB Output is correct
54 Correct 276 ms 3576 KB Output is correct
55 Correct 356 ms 3704 KB Output is correct
56 Correct 243 ms 3576 KB Output is correct
57 Correct 345 ms 3664 KB Output is correct
58 Correct 285 ms 3576 KB Output is correct
59 Correct 304 ms 3576 KB Output is correct
60 Correct 110 ms 2424 KB Output is correct
61 Correct 303 ms 3720 KB Output is correct
62 Correct 298 ms 3704 KB Output is correct
63 Correct 294 ms 3704 KB Output is correct
64 Correct 286 ms 3668 KB Output is correct
65 Correct 243 ms 3320 KB Output is correct
66 Correct 219 ms 3448 KB Output is correct
67 Correct 353 ms 3576 KB Output is correct
68 Correct 153 ms 2424 KB Output is correct
69 Correct 604 ms 4172 KB Output is correct
70 Correct 492 ms 3832 KB Output is correct
71 Correct 487 ms 3704 KB Output is correct
72 Correct 482 ms 3448 KB Output is correct
73 Correct 484 ms 3324 KB Output is correct
74 Correct 621 ms 4088 KB Output is correct
75 Correct 554 ms 4088 KB Output is correct
76 Correct 624 ms 4088 KB Output is correct
77 Correct 641 ms 4088 KB Output is correct