Submission #169946

#TimeUsernameProblemLanguageResultExecution timeMemory
169946DovranBootfall (IZhO17_bootfall)C++11
100 / 100
435 ms3568 KiB
#include <bits/stdc++.h> #define N 1000009 #define pii pair <int, int> #define ff first #define ss second #define pb push_back #define ll long long using namespace std; int n, m, v[N], sum, vis[N], ism; int an[N]; vector<int>ans; int main(){ scanf("%d", &n); for(int i=1; i<=n; i++) scanf("%d", &v[i]), sum+=v[i]; vis[0] = 1; for(int i = 1; i <= n;i++) for(int j = sum; j >= 0; j--) vis[j+v[i]] += vis[j]; if(sum%2==1 or vis[sum/2]==0) return cout<<0, 0; for(int i = 1; i <= n; i++){ for(int j = v[i]; j <= sum;j++) vis[j] -= vis[j - v[i]]; for(int j = 1; j < sum; j++){ if(an[j]<i-1) continue; ism = sum - v[i] + j; if(ism % 2 == 0 and ism / 2 - j >= 0 and vis[ism / 2 - j]) an[j]++; } for(int j = sum; j >= v[i]; j--) vis[j] += vis[j - v[i]]; } for(int i = 1; i <= sum; i++) if(an[i] == n) ans.pb(i); printf("%d\n", ans.size()); for(auto i : ans) printf("%d ", i); }

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:44:27: 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:16:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
bootfall.cpp:18:21: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &v[i]), sum+=v[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...