제출 #92828

#제출 시각아이디문제언어결과실행 시간메모리
92828SamAndBootfall (IZhO17_bootfall)C++17
100 / 100
620 ms124876 KiB
#include <bits/stdc++.h>
using namespace std;
const int N = 502;

int n;
int a[N];
int m;

int u[N * N];
int uu[N * N];
bool t[N][N * N];

int main()
{
    //freopen("input2.txt", "r", stdin);
    cin >> n;
    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        m += a[i];
    }

    u[0] = 1;

    for (int i = 1; i <= n; ++i)
    {
        for (int j = m; j >= 0; --j)
        {
            if (j + a[i] <= m)
                u[j + a[i]] += u[j];
        }
    }

    for (int i = 1; i <= n; ++i)
    {
        memcpy(uu, u, sizeof u);
        for (int j = 0; j <= m; ++j)
        {
            if (j + a[i] <= m)
                uu[j + a[i]] -= uu[j];
        }
        for (int j = 0; j <= m; ++j)
        {
            if (uu[j])
                t[i][j] = true;
        }
    }

    if ((m % 2) == 1 || !u[m / 2])
    {
        cout << 0 << endl;
        return 0;
    }

    vector<int> ans;
    for (int x = 1; x <= m; ++x)
    {
        bool z = true;
        for (int i = 1; i <= n; ++i)
        {
            int y = (m - a[i] + x) / 2;
            if (!((m - a[i] + x) % 2 == 0 && y <= m && t[i][y]))
            {
                z = false;
                break;
            }
        }
        if (z)
            ans.push_back(x);
    }

    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); ++i)
        cout << ans[i] << ' ';
    cout << endl;

    return 0;
}

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

bootfall.cpp: In function 'int main()':
bootfall.cpp:73:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (int i = 0; i < ans.size(); ++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...