Submission #391933

#TimeUsernameProblemLanguageResultExecution timeMemory
391933BartolMBootfall (IZhO17_bootfall)C++17
100 / 100
699 ms3516 KiB
#define DEBUG 1
#include <bits/stdc++.h>

using namespace std;

#define X first
#define Y second
#define mp make_pair
#define pb push_back
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <int, pii> pip;
typedef pair <pii, int> ppi;
typedef pair <ll, ll> pll;

const int INF=0x3f3f3f3f;
const int N=505;
const int MOD=1e9+7;

int n, uk=0;
int p[N], cnt[N*N], dp[N*N];
vector <int> sol;

int add(int a, int b) {
    if (b<0) b+=MOD;
    a+=b;
    if (a>=MOD) a-=MOD;
    return a;
}

void dodaj(int x) {
    for (int i=uk; i>=x; --i) dp[i]=add(dp[i], dp[i-x]);
}

void brisi(int x) {
    for (int i=x; i<=uk; ++i) dp[i]=add(dp[i], -dp[i-x]);
}

void solve() {
    dp[0]=1;
    for (int i=0; i<n; ++i) dodaj(p[i]);
    if (uk%2 || !dp[uk/2]) {
        printf("0\n");
        return;
    }
    for (int i=0; i<n; ++i) {
        brisi(p[i]);
        for (int j=0; j<=uk; ++j) {
            int br=p[i]+2*j-uk;
            if (br>=0 && br<=uk && dp[j]) cnt[br]++;
        }
        dodaj(p[i]);
    }
    for (int i=0; i<=uk; ++i) if (cnt[i]==n) sol.pb(i);
    printf("%d\n", sol.size());
    for (int x:sol) printf("%d ", x);
}

void load() {
    scanf("%d", &n);
    for (int i=0; i<n; ++i) scanf("%d", p+i);
    for (int i=0; i<n; ++i) uk+=p[i];
}

int main() {
    load();
    solve();
    return 0;
}

Compilation message (stderr)

bootfall.cpp: In function 'void solve()':
bootfall.cpp:55:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wformat=]
   55 |     printf("%d\n", sol.size());
      |             ~^     ~~~~~~~~~~
      |              |             |
      |              int           std::vector<int>::size_type {aka long unsigned int}
      |             %ld
bootfall.cpp: In function 'void load()':
bootfall.cpp:60:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   60 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bootfall.cpp:61:34: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   61 |     for (int i=0; i<n; ++i) scanf("%d", p+i);
      |                             ~~~~~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...