Submission #1119062

#TimeUsernameProblemLanguageResultExecution timeMemory
1119062KasymKBootfall (IZhO17_bootfall)C++17
65 / 100
827 ms11172 KiB
#include "bits/stdc++.h"
using namespace std;
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define pli pair<ll, int>
#define pll pair<ll, ll>
#define tr(i, c) for(auto i = c.begin(); i != c.end(); ++i)
#define wr puts("----------------")
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
const int N = 355;
int v[N];
// bool is[N*N];
bitset<N*N> dp, vis[N], tmp;
 
int main(){
    // freopen("file.txt", "r", stdin);
    int n, sm = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n; ++i)
        scanf("%d", v+i), sm += v[i];
    dp[0] = 1;
    for(int i = 1; i <= n; ++i)
        dp=dp|(dp<<v[i]);
    if(sm&1 or !dp[sm/2]){
        puts("0");
        return 0; // Tima's has no possible strengths
    }
    for(int ad = 1; ad <= n; ++ad){
        sm -= v[ad];
        dp.reset();
        dp[0] = 1;
        for(int i = 1; i < ad; ++i)
            dp=dp|(dp<<v[i]);
        for(int i = ad+1; i <= n; ++i)
            dp=dp|(dp<<v[i]);
        for(int i = 0; i <= sm; ++i)
            if(dp[i]){
                int val = abs(sm-2*i);
                vis[ad][val] = 1;
            }
        sm += v[ad];
    }
    tmp = vis[1];
    for(int ad = 2; ad <= n; ++ad){
        tmp = tmp&vis[ad];
    }
    //     for(int i = 0; i <= sm; ++i){
    //         if(!is[i])
    //             continue;
    //         if(!x[ad].count(i))
    //             is[i] = 0;
    //     }
    vector<int> ans;
    for(int i = 0; i <= sm; ++i)
        if(tmp[i])
            ans.pb(i);
    printf("%d\n", (int)ans.size());
    for(auto i : ans)
        printf("%d ", i);
    puts("");
    return 0;
}

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:23:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |     scanf("%d", &n);
      |     ~~~~~^~~~~~~~~~
bootfall.cpp:25:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |         scanf("%d", v+i), sm += v[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...