Submission #36249

# Submission time Handle Problem Language Result Execution time Memory
36249 2017-12-06T13:59:44 Z touristk2000 Bootfall (IZhO17_bootfall) C++14
100 / 100
253 ms 4556 KB
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;
 
#define mk make_pair
#define inb push_back
#define X first
#define Y second
#define all(v) v.begin(), v.end()
#define sqr(x) (x) * (x)
#define TIME 1.0 * clock() / CLOCKS_PER_SEC
#define y1 AYDARBOG

const int BUFSZ = (int)1e5 + 7;
char buf[BUFSZ];
string get_str()
{
    scanf(" %s", buf);
    return string(buf);
}
 
struct Item
{
    int l, r, val;
    Item() {};
    Item(int l, int r, int val) : l(l), r(r), val(val) {};
    void print()
    {
        printf("%d %d %d\n", l, r, val);
    }
};
 
bool intersect(int l, int r, int l1, int r1)
{
    if (l > l1)
        swap(l, l1), swap(r, r1);
    return l1 <= r;
}
 
void dfs(int tl, int tr, int sum, vector<Item> &q, bitset<250001> &dp, vector<int> &cnt)
{
    vector<Item> ql, qr;
    for (auto &x : q)
    {
        if (x.l <= tl && tr <= x.r)
        {
            sum += x.val;
            dp |= dp << x.val;
        }
    }
    if (tl == tr)
    {
        for (int i = 0; i < 250001 && 2 * i < sum; ++i)
        {
            if (!dp[i])
                continue;
            ++cnt[sum - 2 * i];
        }
        return;
    }
    int tm = tl + tr >> 1;
    for (auto &x : q)
    {
        if (x.l <= tl && tr <= x.r)
            continue;
        if (intersect(x.l, x.r, tl, tm))
            ql.inb(x);
        if (intersect(x.l, x.r, tm + 1, tr))
            qr.inb(x);
    }
    q.clear();
    bitset<250001> ndp = dp;
    dfs(tl, tm, sum, ql, dp, cnt);
    dfs(tm + 1, tr, sum, qr, ndp, cnt);
}
 
int solve()
{
    int n;
    scanf("%d", &n);
    vi a(n);
    int sum = 0;
    for (int i = 0; i < n; ++i)
        scanf("%d", &a[i]), sum += a[i];
    vector<int> cnt(250001);
    bitset<250001> dp;
    {
        dp = dp.reset();
        dp[0] = 1;
        for (int i = 0; i < n; ++i)
        {
            dp |= dp << a[i];
        }
        if (!dp[sum / 2])
            puts("0"), exit(0);
    }
    vector<Item> q;
    for (int i = 0; i < n; ++i)
    {
        if (i)
            q.inb(Item(0, i - 1, a[i]));
        if (i < n - 1)
            q.inb(Item(i + 1, n - 1, a[i]));
    }
    dp.reset();
    dp[0] = 1;
    dfs(0, n - 1, 0, q, dp, cnt);
    vi ans;
    for (int i = 0; i < 250001; ++i)
    {
        if (cnt[i] == n)
            ans.inb(i);
    }
    printf("%d\n", (int)ans.size());
    for (int x : ans)
        printf("%d ", x);
    puts("");
    return 0;
}

int main(){
    
    solve();
}

Compilation message

bootfall.cpp: In function 'void dfs(int, int, int, std::vector<Item>&, std::bitset<250001ul>&, std::vector<int>&)':
bootfall.cpp:66:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     int tm = tl + tr >> 1;
                 ^
bootfall.cpp: In function 'std::__cxx11::string get_str()':
bootfall.cpp:23:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf(" %s", buf);
                      ^
bootfall.cpp: In function 'int solve()':
bootfall.cpp:85:20: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
                    ^
bootfall.cpp:89:40: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]), sum += a[i];
                                        ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3248 KB Output is correct
2 Correct 3 ms 3308 KB Output is correct
3 Correct 0 ms 3096 KB Output is correct
4 Correct 0 ms 3244 KB Output is correct
5 Correct 3 ms 3372 KB Output is correct
6 Correct 0 ms 3308 KB Output is correct
7 Correct 0 ms 3304 KB Output is correct
8 Correct 6 ms 3368 KB Output is correct
9 Correct 3 ms 3368 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3248 KB Output is correct
2 Correct 3 ms 3308 KB Output is correct
3 Correct 0 ms 3096 KB Output is correct
4 Correct 0 ms 3244 KB Output is correct
5 Correct 3 ms 3372 KB Output is correct
6 Correct 0 ms 3308 KB Output is correct
7 Correct 0 ms 3304 KB Output is correct
8 Correct 6 ms 3368 KB Output is correct
9 Correct 3 ms 3368 KB Output is correct
10 Correct 3 ms 3428 KB Output is correct
11 Correct 3 ms 3428 KB Output is correct
12 Correct 3 ms 3432 KB Output is correct
13 Correct 0 ms 3428 KB Output is correct
14 Correct 3 ms 3428 KB Output is correct
15 Correct 3 ms 3432 KB Output is correct
16 Correct 3 ms 3428 KB Output is correct
17 Correct 3 ms 3428 KB Output is correct
18 Correct 3 ms 3432 KB Output is correct
19 Correct 3 ms 3428 KB Output is correct
20 Correct 6 ms 3428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3248 KB Output is correct
2 Correct 3 ms 3308 KB Output is correct
3 Correct 0 ms 3096 KB Output is correct
4 Correct 0 ms 3244 KB Output is correct
5 Correct 3 ms 3372 KB Output is correct
6 Correct 0 ms 3308 KB Output is correct
7 Correct 0 ms 3304 KB Output is correct
8 Correct 6 ms 3368 KB Output is correct
9 Correct 3 ms 3368 KB Output is correct
10 Correct 3 ms 3428 KB Output is correct
11 Correct 3 ms 3428 KB Output is correct
12 Correct 3 ms 3432 KB Output is correct
13 Correct 0 ms 3428 KB Output is correct
14 Correct 3 ms 3428 KB Output is correct
15 Correct 3 ms 3432 KB Output is correct
16 Correct 3 ms 3428 KB Output is correct
17 Correct 3 ms 3428 KB Output is correct
18 Correct 3 ms 3432 KB Output is correct
19 Correct 3 ms 3428 KB Output is correct
20 Correct 6 ms 3428 KB Output is correct
21 Correct 9 ms 3492 KB Output is correct
22 Correct 6 ms 3552 KB Output is correct
23 Correct 6 ms 3488 KB Output is correct
24 Correct 9 ms 3552 KB Output is correct
25 Correct 16 ms 3548 KB Output is correct
26 Correct 19 ms 3552 KB Output is correct
27 Correct 16 ms 3552 KB Output is correct
28 Correct 13 ms 3556 KB Output is correct
29 Correct 13 ms 3552 KB Output is correct
30 Correct 13 ms 3556 KB Output is correct
31 Correct 9 ms 3552 KB Output is correct
32 Correct 13 ms 3556 KB Output is correct
33 Correct 13 ms 3556 KB Output is correct
34 Correct 13 ms 3556 KB Output is correct
35 Correct 13 ms 3548 KB Output is correct
36 Correct 16 ms 3552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3248 KB Output is correct
2 Correct 3 ms 3308 KB Output is correct
3 Correct 0 ms 3096 KB Output is correct
4 Correct 0 ms 3244 KB Output is correct
5 Correct 3 ms 3372 KB Output is correct
6 Correct 0 ms 3308 KB Output is correct
7 Correct 0 ms 3304 KB Output is correct
8 Correct 6 ms 3368 KB Output is correct
9 Correct 3 ms 3368 KB Output is correct
10 Correct 3 ms 3428 KB Output is correct
11 Correct 3 ms 3428 KB Output is correct
12 Correct 3 ms 3432 KB Output is correct
13 Correct 0 ms 3428 KB Output is correct
14 Correct 3 ms 3428 KB Output is correct
15 Correct 3 ms 3432 KB Output is correct
16 Correct 3 ms 3428 KB Output is correct
17 Correct 3 ms 3428 KB Output is correct
18 Correct 3 ms 3432 KB Output is correct
19 Correct 3 ms 3428 KB Output is correct
20 Correct 6 ms 3428 KB Output is correct
21 Correct 9 ms 3492 KB Output is correct
22 Correct 6 ms 3552 KB Output is correct
23 Correct 6 ms 3488 KB Output is correct
24 Correct 9 ms 3552 KB Output is correct
25 Correct 16 ms 3548 KB Output is correct
26 Correct 19 ms 3552 KB Output is correct
27 Correct 16 ms 3552 KB Output is correct
28 Correct 13 ms 3556 KB Output is correct
29 Correct 13 ms 3552 KB Output is correct
30 Correct 13 ms 3556 KB Output is correct
31 Correct 9 ms 3552 KB Output is correct
32 Correct 13 ms 3556 KB Output is correct
33 Correct 13 ms 3556 KB Output is correct
34 Correct 13 ms 3556 KB Output is correct
35 Correct 13 ms 3548 KB Output is correct
36 Correct 16 ms 3552 KB Output is correct
37 Correct 36 ms 3756 KB Output is correct
38 Correct 36 ms 3756 KB Output is correct
39 Correct 53 ms 3612 KB Output is correct
40 Correct 56 ms 3828 KB Output is correct
41 Correct 56 ms 3676 KB Output is correct
42 Correct 43 ms 3756 KB Output is correct
43 Correct 49 ms 3884 KB Output is correct
44 Correct 53 ms 3888 KB Output is correct
45 Correct 53 ms 3888 KB Output is correct
46 Correct 46 ms 3672 KB Output is correct
47 Correct 46 ms 3756 KB Output is correct
48 Correct 53 ms 3892 KB Output is correct
49 Correct 49 ms 3760 KB Output is correct
50 Correct 46 ms 3760 KB Output is correct
51 Correct 43 ms 3612 KB Output is correct
52 Correct 66 ms 3968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3248 KB Output is correct
2 Correct 3 ms 3308 KB Output is correct
3 Correct 0 ms 3096 KB Output is correct
4 Correct 0 ms 3244 KB Output is correct
5 Correct 3 ms 3372 KB Output is correct
6 Correct 0 ms 3308 KB Output is correct
7 Correct 0 ms 3304 KB Output is correct
8 Correct 6 ms 3368 KB Output is correct
9 Correct 3 ms 3368 KB Output is correct
10 Correct 3 ms 3428 KB Output is correct
11 Correct 3 ms 3428 KB Output is correct
12 Correct 3 ms 3432 KB Output is correct
13 Correct 0 ms 3428 KB Output is correct
14 Correct 3 ms 3428 KB Output is correct
15 Correct 3 ms 3432 KB Output is correct
16 Correct 3 ms 3428 KB Output is correct
17 Correct 3 ms 3428 KB Output is correct
18 Correct 3 ms 3432 KB Output is correct
19 Correct 3 ms 3428 KB Output is correct
20 Correct 6 ms 3428 KB Output is correct
21 Correct 9 ms 3492 KB Output is correct
22 Correct 6 ms 3552 KB Output is correct
23 Correct 6 ms 3488 KB Output is correct
24 Correct 9 ms 3552 KB Output is correct
25 Correct 16 ms 3548 KB Output is correct
26 Correct 19 ms 3552 KB Output is correct
27 Correct 16 ms 3552 KB Output is correct
28 Correct 13 ms 3556 KB Output is correct
29 Correct 13 ms 3552 KB Output is correct
30 Correct 13 ms 3556 KB Output is correct
31 Correct 9 ms 3552 KB Output is correct
32 Correct 13 ms 3556 KB Output is correct
33 Correct 13 ms 3556 KB Output is correct
34 Correct 13 ms 3556 KB Output is correct
35 Correct 13 ms 3548 KB Output is correct
36 Correct 16 ms 3552 KB Output is correct
37 Correct 36 ms 3756 KB Output is correct
38 Correct 36 ms 3756 KB Output is correct
39 Correct 53 ms 3612 KB Output is correct
40 Correct 56 ms 3828 KB Output is correct
41 Correct 56 ms 3676 KB Output is correct
42 Correct 43 ms 3756 KB Output is correct
43 Correct 49 ms 3884 KB Output is correct
44 Correct 53 ms 3888 KB Output is correct
45 Correct 53 ms 3888 KB Output is correct
46 Correct 46 ms 3672 KB Output is correct
47 Correct 46 ms 3756 KB Output is correct
48 Correct 53 ms 3892 KB Output is correct
49 Correct 49 ms 3760 KB Output is correct
50 Correct 46 ms 3760 KB Output is correct
51 Correct 43 ms 3612 KB Output is correct
52 Correct 66 ms 3968 KB Output is correct
53 Correct 83 ms 3960 KB Output is correct
54 Correct 79 ms 3912 KB Output is correct
55 Correct 106 ms 4168 KB Output is correct
56 Correct 73 ms 3968 KB Output is correct
57 Correct 113 ms 4168 KB Output is correct
58 Correct 79 ms 3904 KB Output is correct
59 Correct 79 ms 4168 KB Output is correct
60 Correct 73 ms 3808 KB Output is correct
61 Correct 93 ms 4168 KB Output is correct
62 Correct 96 ms 4164 KB Output is correct
63 Correct 103 ms 4164 KB Output is correct
64 Correct 93 ms 4164 KB Output is correct
65 Correct 56 ms 3676 KB Output is correct
66 Correct 63 ms 3828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 3248 KB Output is correct
2 Correct 3 ms 3308 KB Output is correct
3 Correct 0 ms 3096 KB Output is correct
4 Correct 0 ms 3244 KB Output is correct
5 Correct 3 ms 3372 KB Output is correct
6 Correct 0 ms 3308 KB Output is correct
7 Correct 0 ms 3304 KB Output is correct
8 Correct 6 ms 3368 KB Output is correct
9 Correct 3 ms 3368 KB Output is correct
10 Correct 3 ms 3428 KB Output is correct
11 Correct 3 ms 3428 KB Output is correct
12 Correct 3 ms 3432 KB Output is correct
13 Correct 0 ms 3428 KB Output is correct
14 Correct 3 ms 3428 KB Output is correct
15 Correct 3 ms 3432 KB Output is correct
16 Correct 3 ms 3428 KB Output is correct
17 Correct 3 ms 3428 KB Output is correct
18 Correct 3 ms 3432 KB Output is correct
19 Correct 3 ms 3428 KB Output is correct
20 Correct 6 ms 3428 KB Output is correct
21 Correct 9 ms 3492 KB Output is correct
22 Correct 6 ms 3552 KB Output is correct
23 Correct 6 ms 3488 KB Output is correct
24 Correct 9 ms 3552 KB Output is correct
25 Correct 16 ms 3548 KB Output is correct
26 Correct 19 ms 3552 KB Output is correct
27 Correct 16 ms 3552 KB Output is correct
28 Correct 13 ms 3556 KB Output is correct
29 Correct 13 ms 3552 KB Output is correct
30 Correct 13 ms 3556 KB Output is correct
31 Correct 9 ms 3552 KB Output is correct
32 Correct 13 ms 3556 KB Output is correct
33 Correct 13 ms 3556 KB Output is correct
34 Correct 13 ms 3556 KB Output is correct
35 Correct 13 ms 3548 KB Output is correct
36 Correct 16 ms 3552 KB Output is correct
37 Correct 36 ms 3756 KB Output is correct
38 Correct 36 ms 3756 KB Output is correct
39 Correct 53 ms 3612 KB Output is correct
40 Correct 56 ms 3828 KB Output is correct
41 Correct 56 ms 3676 KB Output is correct
42 Correct 43 ms 3756 KB Output is correct
43 Correct 49 ms 3884 KB Output is correct
44 Correct 53 ms 3888 KB Output is correct
45 Correct 53 ms 3888 KB Output is correct
46 Correct 46 ms 3672 KB Output is correct
47 Correct 46 ms 3756 KB Output is correct
48 Correct 53 ms 3892 KB Output is correct
49 Correct 49 ms 3760 KB Output is correct
50 Correct 46 ms 3760 KB Output is correct
51 Correct 43 ms 3612 KB Output is correct
52 Correct 66 ms 3968 KB Output is correct
53 Correct 83 ms 3960 KB Output is correct
54 Correct 79 ms 3912 KB Output is correct
55 Correct 106 ms 4168 KB Output is correct
56 Correct 73 ms 3968 KB Output is correct
57 Correct 113 ms 4168 KB Output is correct
58 Correct 79 ms 3904 KB Output is correct
59 Correct 79 ms 4168 KB Output is correct
60 Correct 73 ms 3808 KB Output is correct
61 Correct 93 ms 4168 KB Output is correct
62 Correct 96 ms 4164 KB Output is correct
63 Correct 103 ms 4164 KB Output is correct
64 Correct 93 ms 4164 KB Output is correct
65 Correct 56 ms 3676 KB Output is correct
66 Correct 63 ms 3828 KB Output is correct
67 Correct 103 ms 4168 KB Output is correct
68 Correct 6 ms 3096 KB Output is correct
69 Correct 213 ms 4556 KB Output is correct
70 Correct 166 ms 4176 KB Output is correct
71 Correct 179 ms 4172 KB Output is correct
72 Correct 169 ms 3808 KB Output is correct
73 Correct 163 ms 3804 KB Output is correct
74 Correct 223 ms 4552 KB Output is correct
75 Correct 206 ms 4552 KB Output is correct
76 Correct 253 ms 4552 KB Output is correct
77 Correct 246 ms 4556 KB Output is correct