Submission #38273

# Submission time Handle Problem Language Result Execution time Memory
38273 2018-01-03T10:27:30 Z mirbek01 Bootfall (IZhO17_bootfall) C++14
6 / 100
0 ms 4944 KB
# include <bits/stdc++.h>

# define pb push_back
# define fr first
# define sc second
# define mk make_pair

using namespace std;

const long long linf = 1e18 + 7;
const int inf = 1e9 + 7;
const int N = 250005;

typedef long long ll;

int n, a[N], dp[N], cnt[N], s;
vector <int> ans;

int main(){
      dp[0] = 1;

      scanf("%d", &n);

      for(int i = 1; i <= n; i ++){
            scanf("%d", &a[i]);
            s += a[i];
      }

      for(int i = 1; i <= n; i ++)
            for(int j = s; j - a[i] >= 0; j --)
                  dp[j] += dp[j - a[i]];

      if(s % 2 || !dp[s / 2])
      {
            cout << 0 << endl;
            return 0;
      }

      for(int i = 1; i <= n; i ++){
            int ss = s - a[i];

            for(int j = 0; j <= ss; j ++)
                  dp[j + a[i]] = (dp[j + a[i]] - dp[j]);
            for(int j = ss / 2 + 1; j <= ss; j ++)
                  if(dp[j]) cnt[j * 2 - ss] ++;

            for(int j = ss - a[i]; j >= 0; j --)
                  dp[j + a[i]] += dp[j];
      }

      for(int i = 1; i <= s; i ++)
             if(cnt[i] == n) ans.pb(i);

      printf("%d\n", ans.size());

      for(int i : ans)
            printf("%d ", i);
}

Compilation message

bootfall.cpp: In function 'int main()':
bootfall.cpp:54:32: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::vector<int>::size_type {aka long unsigned int}' [-Wformat=]
       printf("%d\n", ans.size());
                                ^
bootfall.cpp:22:22: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
       scanf("%d", &n);
                      ^
bootfall.cpp:25:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
             scanf("%d", &a[i]);
                               ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4944 KB Output is correct
2 Correct 0 ms 4944 KB Output is correct
3 Correct 0 ms 4944 KB Output is correct
4 Correct 0 ms 4944 KB Output is correct
5 Correct 0 ms 4944 KB Output is correct
6 Correct 0 ms 4944 KB Output is correct
7 Correct 0 ms 4944 KB Output is correct
8 Correct 0 ms 4944 KB Output is correct
9 Correct 0 ms 4944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4944 KB Output is correct
2 Correct 0 ms 4944 KB Output is correct
3 Correct 0 ms 4944 KB Output is correct
4 Correct 0 ms 4944 KB Output is correct
5 Correct 0 ms 4944 KB Output is correct
6 Correct 0 ms 4944 KB Output is correct
7 Correct 0 ms 4944 KB Output is correct
8 Correct 0 ms 4944 KB Output is correct
9 Correct 0 ms 4944 KB Output is correct
10 Correct 0 ms 4944 KB Output is correct
11 Correct 0 ms 4944 KB Output is correct
12 Correct 0 ms 4944 KB Output is correct
13 Correct 0 ms 4944 KB Output is correct
14 Incorrect 0 ms 4944 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4944 KB Output is correct
2 Correct 0 ms 4944 KB Output is correct
3 Correct 0 ms 4944 KB Output is correct
4 Correct 0 ms 4944 KB Output is correct
5 Correct 0 ms 4944 KB Output is correct
6 Correct 0 ms 4944 KB Output is correct
7 Correct 0 ms 4944 KB Output is correct
8 Correct 0 ms 4944 KB Output is correct
9 Correct 0 ms 4944 KB Output is correct
10 Correct 0 ms 4944 KB Output is correct
11 Correct 0 ms 4944 KB Output is correct
12 Correct 0 ms 4944 KB Output is correct
13 Correct 0 ms 4944 KB Output is correct
14 Incorrect 0 ms 4944 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4944 KB Output is correct
2 Correct 0 ms 4944 KB Output is correct
3 Correct 0 ms 4944 KB Output is correct
4 Correct 0 ms 4944 KB Output is correct
5 Correct 0 ms 4944 KB Output is correct
6 Correct 0 ms 4944 KB Output is correct
7 Correct 0 ms 4944 KB Output is correct
8 Correct 0 ms 4944 KB Output is correct
9 Correct 0 ms 4944 KB Output is correct
10 Correct 0 ms 4944 KB Output is correct
11 Correct 0 ms 4944 KB Output is correct
12 Correct 0 ms 4944 KB Output is correct
13 Correct 0 ms 4944 KB Output is correct
14 Incorrect 0 ms 4944 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4944 KB Output is correct
2 Correct 0 ms 4944 KB Output is correct
3 Correct 0 ms 4944 KB Output is correct
4 Correct 0 ms 4944 KB Output is correct
5 Correct 0 ms 4944 KB Output is correct
6 Correct 0 ms 4944 KB Output is correct
7 Correct 0 ms 4944 KB Output is correct
8 Correct 0 ms 4944 KB Output is correct
9 Correct 0 ms 4944 KB Output is correct
10 Correct 0 ms 4944 KB Output is correct
11 Correct 0 ms 4944 KB Output is correct
12 Correct 0 ms 4944 KB Output is correct
13 Correct 0 ms 4944 KB Output is correct
14 Incorrect 0 ms 4944 KB Output isn't correct
15 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 4944 KB Output is correct
2 Correct 0 ms 4944 KB Output is correct
3 Correct 0 ms 4944 KB Output is correct
4 Correct 0 ms 4944 KB Output is correct
5 Correct 0 ms 4944 KB Output is correct
6 Correct 0 ms 4944 KB Output is correct
7 Correct 0 ms 4944 KB Output is correct
8 Correct 0 ms 4944 KB Output is correct
9 Correct 0 ms 4944 KB Output is correct
10 Correct 0 ms 4944 KB Output is correct
11 Correct 0 ms 4944 KB Output is correct
12 Correct 0 ms 4944 KB Output is correct
13 Correct 0 ms 4944 KB Output is correct
14 Incorrect 0 ms 4944 KB Output isn't correct
15 Halted 0 ms 0 KB -