Submission #566468

#TimeUsernameProblemLanguageResultExecution timeMemory
566468birthdaycakeBootfall (IZhO17_bootfall)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h> #define endl '\n' #define int long long #define mod 1000000007 #define boost ios_base::sync_with_stdio(false), cin.tie(NULL); using namespace std; int a[200001],dp[2000001],cnt[2000001]; int sum = 0; void remove(int x){ for(int i = x; i <= sum; i++){ dp[i] -= dp[i - x]; dp[i] += mod; dp[i] %= mod; } } void put(int x){ for(int i = sum; i >= x; i--){ dp[i] += dp[i- x]; dp[i] %= mod; } } signed main(){ boost; int n; cin >> n; for(int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } dp[0] = 1; for(int i = 0; i < n; i++){ for(int k = sum; k >= 1; k--){ if(k - a[i] >= 0){ dp[k] += dp[k - a[i]]; dp[k] %= mod; } } } if(sum % 2 || dp[sum / 2] == 0){ cout << 0; return 0; } vector<int>ans; for(int i = 0; i < n; i++){ remove(a[i]); sum -= a[i]; for(int j = 0; j <= sum; j++){ if(dp[j]){ int other = sum - j; if(other - j <= 0) continue; cnt[other - j]++; if(cnt[other - j] == n) ans.push_back(other - j); } } put(a[i]); sum += a[i]; } sort(ans.begin(),ans.end()); cout << ans.size() << endl; for(auto s:ans) cout << s << ' ' ; return 0; } #include<bits/stdc++.h> #define endl '\n' #define int long long #define mod 1000000007 #define boost ios_base::sync_with_stdio(false), cin.tie(NULL); using namespace std; int a[200001],dp[2000001],cnt[2000001]; int sum = 0; void remove(int x){ for(int i = x; i <= sum; i++){ dp[i] -= dp[i - x]; dp[i] += mod; dp[i] %= mod; } } void put(int x){ for(int i = sum; i >= x; i--){ dp[i] += dp[i- x]; dp[i] %= mod; } } signed main(){ boost; int n; cin >> n; for(int i = 0; i < n; i++) { cin >> a[i]; sum += a[i]; } dp[0] = 1; for(int i = 0; i < n; i++){ for(int k = sum; k >= 1; k--){ if(k - a[i] >= 0){ dp[k] += dp[k - a[i]]; dp[k] %= mod; } } } if(sum % 2 || dp[sum / 2] == 0){ cout << 0; return 0; } vector<int>ans; for(int i = 0; i < n; i++){ remove(a[i]); sum -= a[i]; for(int j = 0; j <= sum; j++){ if(dp[j]){ int other = sum - j; if(other - j <= 0) continue; cnt[other - j]++; if(cnt[other - j] == n) ans.push_back(other - j); } } put(a[i]); sum += a[i]; } sort(ans.begin(),ans.end()); cout << ans.size() << endl; for(auto s:ans) cout << s << ' ' ; return 0; } v

Compilation message (stderr)

bootfall.cpp:87:5: error: redefinition of 'long long int a [200001]'
   87 | int a[200001],dp[2000001],cnt[2000001];
      |     ^
bootfall.cpp:11:5: note: 'long long int a [200001]' previously declared here
   11 | int a[200001],dp[2000001],cnt[2000001];
      |     ^
bootfall.cpp:87:15: error: redefinition of 'long long int dp [2000001]'
   87 | int a[200001],dp[2000001],cnt[2000001];
      |               ^~
bootfall.cpp:11:15: note: 'long long int dp [2000001]' previously declared here
   11 | int a[200001],dp[2000001],cnt[2000001];
      |               ^~
bootfall.cpp:87:27: error: redefinition of 'long long int cnt [2000001]'
   87 | int a[200001],dp[2000001],cnt[2000001];
      |                           ^~~
bootfall.cpp:11:27: note: 'long long int cnt [2000001]' previously declared here
   11 | int a[200001],dp[2000001],cnt[2000001];
      |                           ^~~
bootfall.cpp:88:5: error: redefinition of 'long long int sum'
   88 | int sum = 0;
      |     ^~~
bootfall.cpp:12:5: note: 'long long int sum' previously defined here
   12 | int sum = 0;
      |     ^~~
bootfall.cpp:90:6: error: redefinition of 'void remove(long long int)'
   90 | void remove(int x){
      |      ^~~~~~
bootfall.cpp:14:6: note: 'void remove(long long int)' previously defined here
   14 | void remove(int x){
      |      ^~~~~~
bootfall.cpp:99:6: error: redefinition of 'void put(long long int)'
   99 | void put(int x){
      |      ^~~
bootfall.cpp:23:6: note: 'void put(long long int)' previously defined here
   23 | void put(int x){
      |      ^~~
bootfall.cpp:107:8: error: redefinition of 'int main()'
  107 | signed main(){
      |        ^~~~
bootfall.cpp:31:8: note: 'int main()' previously defined here
   31 | signed main(){
      |        ^~~~
bootfall.cpp:153:1: error: 'v' does not name a type
  153 | v
      | ^