답안 #333004

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
333004 2020-12-04T08:43:48 Z Dymo Bootfall (IZhO17_bootfall) C++14
100 / 100
228 ms 3324 KB
#include<bits/stdc++.h>
using namespace std;


#define pb    push_back
#define eb   emplace_back
#define ll  long long
#define pll pair<ll,ll>
#define ff first
#define ss second
#define endl "\n"
const ll maxn=500*500+10;
const ll mod =1e9+7 ;
const ll base=1e18;
const ll block=1000;
/// con 0 ngay nua
/// zesitahn
ll a[maxn];
bitset<maxn> st1;
ll t=0;
void dosth(ll l,ll r,bitset<maxn> st)
{
    if (l==r)
    {
        bitset<maxn>chk;
         for (int i=1;i<maxn;i++)
         {
           ll cl=t-a[l]-i;
           if (cl<0) break;
           if (cl%2==0)
           {
               cl/=2;

               if (st[cl]==1) chk[i]=1;
           }
         }
         st1&=chk;
         return ;
    }
    ll mid=(l+r)/2;
    auto nxt=st;
    for (int i=mid+1;i<=r;i++)
    {
        nxt|=(nxt<<a[i]);
    }
    dosth(l,mid,nxt);
    nxt=st;
    for (int i=l;i<=mid;i++)
    {
        nxt|=(nxt<<a[i]);
    }
    dosth(mid+1, r, nxt);
}
bool chk(ll n)
{
   if (t%2==1) return false;
   bitset<maxn> st;
   st[0]=1;
   for (int i=1;i<=n;i++)
   {
       st|=(st<<a[i]);
   }
 //  cout <<t/2<<endl;
   return st[t/2];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    if (fopen("queue.inp", "r"))
    {
        freopen("queue.inp", "r", stdin);
        freopen("queue.out", "w", stdout);
    }
    ll n;
     cin>> n;
     for (int i=1;i<=n;i++)
     {
         cin>>a[i];
         t+=a[i];
     }
     if (!chk(n))
     {
         cout <<0;
         return 0;
     }
     bitset<maxn> st;
     st[0]=1;
     for (int i=1;i<maxn;i++)
     {
         st1[i]=1;
     }
     dosth(1,n,st);
     vector<ll> ans;
     for (int i=1;i<maxn;i++)
     {
         if (st1[i]) ans.pb(i);
     }
     cout <<ans.size()<<endl;
     for (auto to:ans)
     {
         cout <<to<<" ";
     }

}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:73:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   73 |         freopen("queue.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
bootfall.cpp:74:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
   74 |         freopen("queue.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 4 ms 1132 KB Output is correct
11 Correct 4 ms 1132 KB Output is correct
12 Correct 4 ms 1132 KB Output is correct
13 Correct 3 ms 1132 KB Output is correct
14 Correct 4 ms 1132 KB Output is correct
15 Correct 3 ms 1132 KB Output is correct
16 Correct 4 ms 1132 KB Output is correct
17 Correct 3 ms 1132 KB Output is correct
18 Correct 3 ms 1132 KB Output is correct
19 Correct 3 ms 1132 KB Output is correct
20 Correct 4 ms 1132 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 4 ms 1132 KB Output is correct
11 Correct 4 ms 1132 KB Output is correct
12 Correct 4 ms 1132 KB Output is correct
13 Correct 3 ms 1132 KB Output is correct
14 Correct 4 ms 1132 KB Output is correct
15 Correct 3 ms 1132 KB Output is correct
16 Correct 4 ms 1132 KB Output is correct
17 Correct 3 ms 1132 KB Output is correct
18 Correct 3 ms 1132 KB Output is correct
19 Correct 3 ms 1132 KB Output is correct
20 Correct 4 ms 1132 KB Output is correct
21 Correct 7 ms 1280 KB Output is correct
22 Correct 8 ms 1388 KB Output is correct
23 Correct 6 ms 1260 KB Output is correct
24 Correct 10 ms 1388 KB Output is correct
25 Correct 11 ms 1388 KB Output is correct
26 Correct 11 ms 1388 KB Output is correct
27 Correct 11 ms 1388 KB Output is correct
28 Correct 12 ms 1408 KB Output is correct
29 Correct 11 ms 1388 KB Output is correct
30 Correct 11 ms 1260 KB Output is correct
31 Correct 11 ms 1388 KB Output is correct
32 Correct 10 ms 1388 KB Output is correct
33 Correct 11 ms 1260 KB Output is correct
34 Correct 11 ms 1260 KB Output is correct
35 Correct 11 ms 1260 KB Output is correct
36 Correct 11 ms 1388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 4 ms 1132 KB Output is correct
11 Correct 4 ms 1132 KB Output is correct
12 Correct 4 ms 1132 KB Output is correct
13 Correct 3 ms 1132 KB Output is correct
14 Correct 4 ms 1132 KB Output is correct
15 Correct 3 ms 1132 KB Output is correct
16 Correct 4 ms 1132 KB Output is correct
17 Correct 3 ms 1132 KB Output is correct
18 Correct 3 ms 1132 KB Output is correct
19 Correct 3 ms 1132 KB Output is correct
20 Correct 4 ms 1132 KB Output is correct
21 Correct 7 ms 1280 KB Output is correct
22 Correct 8 ms 1388 KB Output is correct
23 Correct 6 ms 1260 KB Output is correct
24 Correct 10 ms 1388 KB Output is correct
25 Correct 11 ms 1388 KB Output is correct
26 Correct 11 ms 1388 KB Output is correct
27 Correct 11 ms 1388 KB Output is correct
28 Correct 12 ms 1408 KB Output is correct
29 Correct 11 ms 1388 KB Output is correct
30 Correct 11 ms 1260 KB Output is correct
31 Correct 11 ms 1388 KB Output is correct
32 Correct 10 ms 1388 KB Output is correct
33 Correct 11 ms 1260 KB Output is correct
34 Correct 11 ms 1260 KB Output is correct
35 Correct 11 ms 1260 KB Output is correct
36 Correct 11 ms 1388 KB Output is correct
37 Correct 26 ms 1644 KB Output is correct
38 Correct 29 ms 1644 KB Output is correct
39 Correct 43 ms 1388 KB Output is correct
40 Correct 40 ms 1900 KB Output is correct
41 Correct 58 ms 1516 KB Output is correct
42 Correct 36 ms 1772 KB Output is correct
43 Correct 44 ms 1904 KB Output is correct
44 Correct 45 ms 1904 KB Output is correct
45 Correct 46 ms 1888 KB Output is correct
46 Correct 37 ms 1516 KB Output is correct
47 Correct 37 ms 1772 KB Output is correct
48 Correct 46 ms 1776 KB Output is correct
49 Correct 45 ms 1644 KB Output is correct
50 Correct 36 ms 1772 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 57 ms 2180 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 4 ms 1132 KB Output is correct
11 Correct 4 ms 1132 KB Output is correct
12 Correct 4 ms 1132 KB Output is correct
13 Correct 3 ms 1132 KB Output is correct
14 Correct 4 ms 1132 KB Output is correct
15 Correct 3 ms 1132 KB Output is correct
16 Correct 4 ms 1132 KB Output is correct
17 Correct 3 ms 1132 KB Output is correct
18 Correct 3 ms 1132 KB Output is correct
19 Correct 3 ms 1132 KB Output is correct
20 Correct 4 ms 1132 KB Output is correct
21 Correct 7 ms 1280 KB Output is correct
22 Correct 8 ms 1388 KB Output is correct
23 Correct 6 ms 1260 KB Output is correct
24 Correct 10 ms 1388 KB Output is correct
25 Correct 11 ms 1388 KB Output is correct
26 Correct 11 ms 1388 KB Output is correct
27 Correct 11 ms 1388 KB Output is correct
28 Correct 12 ms 1408 KB Output is correct
29 Correct 11 ms 1388 KB Output is correct
30 Correct 11 ms 1260 KB Output is correct
31 Correct 11 ms 1388 KB Output is correct
32 Correct 10 ms 1388 KB Output is correct
33 Correct 11 ms 1260 KB Output is correct
34 Correct 11 ms 1260 KB Output is correct
35 Correct 11 ms 1260 KB Output is correct
36 Correct 11 ms 1388 KB Output is correct
37 Correct 26 ms 1644 KB Output is correct
38 Correct 29 ms 1644 KB Output is correct
39 Correct 43 ms 1388 KB Output is correct
40 Correct 40 ms 1900 KB Output is correct
41 Correct 58 ms 1516 KB Output is correct
42 Correct 36 ms 1772 KB Output is correct
43 Correct 44 ms 1904 KB Output is correct
44 Correct 45 ms 1904 KB Output is correct
45 Correct 46 ms 1888 KB Output is correct
46 Correct 37 ms 1516 KB Output is correct
47 Correct 37 ms 1772 KB Output is correct
48 Correct 46 ms 1776 KB Output is correct
49 Correct 45 ms 1644 KB Output is correct
50 Correct 36 ms 1772 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 57 ms 2180 KB Output is correct
53 Correct 50 ms 2032 KB Output is correct
54 Correct 66 ms 2032 KB Output is correct
55 Correct 91 ms 2540 KB Output is correct
56 Correct 56 ms 2032 KB Output is correct
57 Correct 94 ms 2412 KB Output is correct
58 Correct 66 ms 2160 KB Output is correct
59 Correct 74 ms 2160 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 79 ms 2284 KB Output is correct
62 Correct 79 ms 2412 KB Output is correct
63 Correct 80 ms 2412 KB Output is correct
64 Correct 79 ms 2412 KB Output is correct
65 Correct 54 ms 1644 KB Output is correct
66 Correct 55 ms 1772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 748 KB Output is correct
2 Correct 2 ms 876 KB Output is correct
3 Correct 1 ms 492 KB Output is correct
4 Correct 2 ms 748 KB Output is correct
5 Correct 2 ms 1004 KB Output is correct
6 Correct 2 ms 876 KB Output is correct
7 Correct 2 ms 876 KB Output is correct
8 Correct 2 ms 1004 KB Output is correct
9 Correct 2 ms 1004 KB Output is correct
10 Correct 4 ms 1132 KB Output is correct
11 Correct 4 ms 1132 KB Output is correct
12 Correct 4 ms 1132 KB Output is correct
13 Correct 3 ms 1132 KB Output is correct
14 Correct 4 ms 1132 KB Output is correct
15 Correct 3 ms 1132 KB Output is correct
16 Correct 4 ms 1132 KB Output is correct
17 Correct 3 ms 1132 KB Output is correct
18 Correct 3 ms 1132 KB Output is correct
19 Correct 3 ms 1132 KB Output is correct
20 Correct 4 ms 1132 KB Output is correct
21 Correct 7 ms 1280 KB Output is correct
22 Correct 8 ms 1388 KB Output is correct
23 Correct 6 ms 1260 KB Output is correct
24 Correct 10 ms 1388 KB Output is correct
25 Correct 11 ms 1388 KB Output is correct
26 Correct 11 ms 1388 KB Output is correct
27 Correct 11 ms 1388 KB Output is correct
28 Correct 12 ms 1408 KB Output is correct
29 Correct 11 ms 1388 KB Output is correct
30 Correct 11 ms 1260 KB Output is correct
31 Correct 11 ms 1388 KB Output is correct
32 Correct 10 ms 1388 KB Output is correct
33 Correct 11 ms 1260 KB Output is correct
34 Correct 11 ms 1260 KB Output is correct
35 Correct 11 ms 1260 KB Output is correct
36 Correct 11 ms 1388 KB Output is correct
37 Correct 26 ms 1644 KB Output is correct
38 Correct 29 ms 1644 KB Output is correct
39 Correct 43 ms 1388 KB Output is correct
40 Correct 40 ms 1900 KB Output is correct
41 Correct 58 ms 1516 KB Output is correct
42 Correct 36 ms 1772 KB Output is correct
43 Correct 44 ms 1904 KB Output is correct
44 Correct 45 ms 1904 KB Output is correct
45 Correct 46 ms 1888 KB Output is correct
46 Correct 37 ms 1516 KB Output is correct
47 Correct 37 ms 1772 KB Output is correct
48 Correct 46 ms 1776 KB Output is correct
49 Correct 45 ms 1644 KB Output is correct
50 Correct 36 ms 1772 KB Output is correct
51 Correct 1 ms 364 KB Output is correct
52 Correct 57 ms 2180 KB Output is correct
53 Correct 50 ms 2032 KB Output is correct
54 Correct 66 ms 2032 KB Output is correct
55 Correct 91 ms 2540 KB Output is correct
56 Correct 56 ms 2032 KB Output is correct
57 Correct 94 ms 2412 KB Output is correct
58 Correct 66 ms 2160 KB Output is correct
59 Correct 74 ms 2160 KB Output is correct
60 Correct 1 ms 364 KB Output is correct
61 Correct 79 ms 2284 KB Output is correct
62 Correct 79 ms 2412 KB Output is correct
63 Correct 80 ms 2412 KB Output is correct
64 Correct 79 ms 2412 KB Output is correct
65 Correct 54 ms 1644 KB Output is correct
66 Correct 55 ms 1772 KB Output is correct
67 Correct 88 ms 2316 KB Output is correct
68 Correct 5 ms 492 KB Output is correct
69 Correct 206 ms 3176 KB Output is correct
70 Correct 142 ms 2668 KB Output is correct
71 Correct 140 ms 2540 KB Output is correct
72 Correct 139 ms 1516 KB Output is correct
73 Correct 136 ms 1516 KB Output is correct
74 Correct 208 ms 3324 KB Output is correct
75 Correct 176 ms 2920 KB Output is correct
76 Correct 228 ms 3160 KB Output is correct
77 Correct 225 ms 3304 KB Output is correct