답안 #725553

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
725553 2023-04-17T15:48:51 Z vjudge1 Bootfall (IZhO17_bootfall) C++17
0 / 100
1000 ms 340 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ld long double
#define ll long long
#define S second
#define F first

using namespace __gnu_pbds;
using namespace std;

typedef tree<long long, null_type, less_equal<long long>,
    rb_tree_tag, tree_order_statistics_node_update> Tree;

const ll INF = 9223372036854775807LL;
const ll inf = 2147483647;
const ll MAXN = 300010;
const ll MOD = 1e9 + 7;
const ld PI = acos(-1);
const ll NROOT = 320;

ll binpow(ll a, ll b) {
  ll res = 1;
  for (;b; b /= 2, a *= a, a %= MOD)
    if (b & 1) res *= a, res %= MOD;
  return res % MOD;
}

ll gcd(ll a, ll b) {return b ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b) {return a * b / gcd(a, b);}
ll invmod(ll a) {return binpow(a, MOD - 2);}

bool dp(int i, vector<int> &v, int s1, int s2) {
  if (i == v.size()) {
    if (s1 == s2) return 1;
    else return 0;
  }

  bool ans = 0;
  ans |= dp(i + 1, v, s1 + v[i], s2); 
  ans |= dp(i + 1, v, s1, s2 + v[i]);
  return ans;
}

int32_t main () {
  ios_base::sync_with_stdio(false); 
  cin.tie(nullptr);

  int n; cin >> n;
  vector<int> v(n + 1);
  int sum = 0;
  for (int i = 1; i <= n; i ++) {
    cin >> v[i];
    sum += v[i];
  }

  vector<int> ans;
  
  for (int i = 1; i <= sum; i ++) {
    v[0] = i;
    bool ok = 1;
    for (int j = 0; j <= n; j ++) {
      int x = v[j];
      v[j] = 0;
      if (!dp(0, v, 0, 0)) {
        ok = 0;
      }
      v[j] = x;
    }
    if (ok) ans.push_back(i);
  }

  cout << ans.size() << '\n';
  for (auto &x : ans)
    cout << x << " ";

  return 0;
}

Compilation message

bootfall.cpp: In function 'bool dp(int, std::vector<int>&, int, int)':
bootfall.cpp:34:9: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |   if (i == v.size()) {
      |       ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 602 ms 300 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Execution timed out 1022 ms 340 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 602 ms 300 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Execution timed out 1022 ms 340 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 602 ms 300 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Execution timed out 1022 ms 340 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 602 ms 300 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Execution timed out 1022 ms 340 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 602 ms 300 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Execution timed out 1022 ms 340 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 328 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 316 KB Output is correct
4 Correct 2 ms 212 KB Output is correct
5 Correct 602 ms 300 KB Output is correct
6 Correct 6 ms 212 KB Output is correct
7 Correct 2 ms 320 KB Output is correct
8 Execution timed out 1022 ms 340 KB Time limit exceeded
9 Halted 0 ms 0 KB -