제출 #1177002

#제출 시각아이디문제언어결과실행 시간메모리
1177002CrabCNHBootfall (IZhO17_bootfall)C++20
100 / 100
360 ms5808 KiB
#include <bits/stdc++.h>

#define task   "BriantheCrab"

#define int    long long
#define pii    pair <int, int>
#define fi     first
#define se     second
#define szf    sizeof
#define sz(s)  (int)((s).size())

using namespace std;

template <class T> void mini (T &t, T f) {if (t > f) t = f;}
template <class T> void maxi (T &t, T f) {if (t < f) t = f;}

const int maxN = 500 + 5;
const int inf = 1e18 + 7;
const int mod = 1e9 + 7;

int n, sum = 0;
int dp[maxN * maxN], cnt[maxN * maxN]; 
int a[maxN];

inline void add (int x) {
    for (int s = sum; s >= x; s --) {
        dp[s] += dp[s - x];
    }
}

inline void del (int x) {
    for (int s = x; s <= sum; s ++) {
        dp[s] -= dp[s - x];
    }
}

void solve () {
    cin >> n;
    for (int i = 1; i <= n; i ++) {
        cin >> a[i];
        sum += a[i];
    }
    dp[0] = 1;
    for (int i = 1; i <= n; i ++) {
        add (a[i]);
    }
    if (sum % 2 == 1 || dp[sum / 2] == 0) {
        cout << "0";
        return;
    }
    for (int i = 1; i <= n; i ++) {
        del (a[i]);
        for (int s = 0; s <= sum - a[i]; s ++) {
            if (dp[s]) {
                int left = sum - a[i] - s;
                cnt[max (left - s, 0LL)] ++;
            }
        }
        add (a[i]);
    }
    vector <int> res;
    for (int s = 1; s <= sum; s ++) {
        if (cnt[s] == n) {
            res.push_back (s);
        }
    }
    cout << res.size () << '\n';
    for (auto u : res) {
        cout << u << ' ';
    }
    return;
    
}

signed main () {
    cin.tie (nullptr) -> sync_with_stdio (false);
    if (fopen (task".inp", "r")) {
        freopen (task".inp", "r", stdin);
        freopen (task".out", "w", stdout);
    }
    int t = 1;
    //cin >> t;
    while (t --) {
        solve ();
    } 
    return 0;
}
// thfdgb

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

bootfall.cpp: In function 'int main()':
bootfall.cpp:78:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   78 |         freopen (task".inp", "r", stdin);
      |         ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:79:17: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   79 |         freopen (task".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...