답안 #677768

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
677768 2023-01-04T10:45:35 Z Mher Bootfall (IZhO17_bootfall) C++14
13 / 100
1000 ms 5308 KB
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#include <queue>

using namespace std;

const int N = 503, mod = 1e9 + 7;

int n, sum = 0;
int a[N];
set<int> dp[N];

void solve()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    if (sum % 2 == 1)
    {
        cout << 0 << endl;
        return;
    }
    dp[0].insert(0);
    for (int i = 1; i <= n; i++)
    {
        set<int> nw;
        for (auto s : dp[0])
        {
            nw.insert(s + a[i]);
        }
        dp[0].insert(nw.begin(), nw.end());
    }
    if (dp[0].count(sum / 2) == 0)
    {
        cout << 0 << endl;
        return;
    }
    for (int k = 1; k <= n; k++)
    {
        dp[k].insert(0);
        for (int i = 1; i <= n; i++)
        {
            if (i == k)
                continue;
            set<int> nw;
            for (auto s : dp[k])
            {
                nw.insert(s + a[i]);
            }
            dp[k].insert(nw.begin(), nw.end());
        }
        int ns = sum - a[k];
        set<int> nt;
        for (auto s : dp[k])
        {
            int kx = ns - 2 * s;
            if (kx >= 0)
            {
                nt.insert(kx);
            }
        }
        dp[k] = nt;
    }
    set<int> ans = dp[1];
    for (int i = 2; i <= n; i++)
    {
        set<int> el;
        for (auto s : ans)
        {
            if (dp[i].count(s) == 0)
                el.insert(s);
        }
        for (auto s : el)
            ans.erase(s);
    }
    cout << ans.size() << endl;
    for (auto s : ans)
    {
        cout << s << ' ';
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //cin >> t;
    while (t--)
        solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 17 ms 496 KB Output is correct
12 Correct 10 ms 436 KB Output is correct
13 Correct 11 ms 476 KB Output is correct
14 Correct 14 ms 476 KB Output is correct
15 Correct 10 ms 476 KB Output is correct
16 Correct 11 ms 468 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 8 ms 468 KB Output is correct
19 Correct 8 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 17 ms 496 KB Output is correct
12 Correct 10 ms 436 KB Output is correct
13 Correct 11 ms 476 KB Output is correct
14 Correct 14 ms 476 KB Output is correct
15 Correct 10 ms 476 KB Output is correct
16 Correct 11 ms 468 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 8 ms 468 KB Output is correct
19 Correct 8 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Execution timed out 1087 ms 5308 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 17 ms 496 KB Output is correct
12 Correct 10 ms 436 KB Output is correct
13 Correct 11 ms 476 KB Output is correct
14 Correct 14 ms 476 KB Output is correct
15 Correct 10 ms 476 KB Output is correct
16 Correct 11 ms 468 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 8 ms 468 KB Output is correct
19 Correct 8 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Execution timed out 1087 ms 5308 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 17 ms 496 KB Output is correct
12 Correct 10 ms 436 KB Output is correct
13 Correct 11 ms 476 KB Output is correct
14 Correct 14 ms 476 KB Output is correct
15 Correct 10 ms 476 KB Output is correct
16 Correct 11 ms 468 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 8 ms 468 KB Output is correct
19 Correct 8 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Execution timed out 1087 ms 5308 KB Time limit exceeded
22 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 0 ms 344 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 4 ms 468 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 4 ms 468 KB Output is correct
9 Correct 2 ms 340 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 17 ms 496 KB Output is correct
12 Correct 10 ms 436 KB Output is correct
13 Correct 11 ms 476 KB Output is correct
14 Correct 14 ms 476 KB Output is correct
15 Correct 10 ms 476 KB Output is correct
16 Correct 11 ms 468 KB Output is correct
17 Correct 4 ms 340 KB Output is correct
18 Correct 8 ms 468 KB Output is correct
19 Correct 8 ms 468 KB Output is correct
20 Correct 1 ms 340 KB Output is correct
21 Execution timed out 1087 ms 5308 KB Time limit exceeded
22 Halted 0 ms 0 KB -