제출 #1176243

#제출 시각아이디문제언어결과실행 시간메모리
1176243hoa208Bootfall (IZhO17_bootfall)C++20
0 / 100
0 ms396 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i >= _a; i--)
#define pa pair<ll, ll>
#define fi first
#define se second
#define bit(mask, j) ((mask >> j) & 1)
#define t_test int t;cin >> t;while(t--)
const   ll mod = 1e9 + 7;
const   ll INF = 1e18;
inline  void adm(ll &x){if(x>=mod)x%=mod;else if(x<0)x+=mod;}
//--------------------------------------------------------------------
const ll N = 503;
ll n, a[N];
ll s[N];
ll dp[N * N];
bitset<N> dx[N], ans;
void hbmt() {
    cin >> n;
    FOR(i, 1, n) {
        cin >> a[i];
        s[i] = s[i - 1] + a[i];
    }
    ans.set();
    dp[0] = 1;
    FOR(i, 1, n) {
        FORD(j, s[n], a[i]) {
            dp[j] += dp[j - a[i]];
            adm(dp[j]);
        }
    }
    FORD(c, n, 1) {
        ll sum = s[n] - a[c];
        FOR(j, a[c], s[n]) {
            dp[j] -= dp[j - a[c]];
            adm(dp[j]);
        }
        FOR(i, 0, s[n]) {
            ll sza = i, szb = sum - i;
            if(dp[i] == 0) continue;
            ll x = abs(sza - szb);
            dx[c][x] = 1;
        }
        ans = (ans & dx[c]);
        FORD(j, s[n], a[c]) {
            dp[j] += dp[j - a[c]];
            adm(dp[j]);
        }
    }
    cout << ans.count() << '\n';
    FOR(i, 1, N - 1) {
        if(ans[i] == 1) {
            cout << i << ' ';
        }
    }
}

int main() {
    
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    
    if(fopen("hbmt.inp", "r")) {
        freopen("hbmt.inp", "r", stdin);
        freopen("hbmt.out", "w", stdout);
    }
    
    // t_test 
    hbmt();
    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

bootfall.cpp: In function 'int main()':
bootfall.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen("hbmt.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen("hbmt.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...