Submission #598438

#TimeUsernameProblemLanguageResultExecution timeMemory
598438SuffixAutomataBootfall (IZhO17_bootfall)C++17
100 / 100
556 ms3708 KiB
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int dp[500 * 500 + 1], dp2[500 * 500 + 1];
bool ok[500 * 500 + 1];
int main() {
  int n;
  cin >> n;
  vector<int> ar(n);
  int sm = 0;
  dp[0] = 1;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
    for (int j = sm; j >= 0; j--)
      dp[j + ar[i]] = (dp[j + ar[i]] + dp[j]) % MOD;
    sm += ar[i];
  }
  auto x = [&](int i) {
    if (i < 0 || i % 2 || i / 2 > sm)
      return 0;
    return dp2[i / 2];
  };
  vector<int> ans;
  if (sm % 2 == 0 && dp[sm / 2]) {
    for (int v = 0; v <= 500 * 500; v++)
      ok[v] = 1;
    for (int i : ar) {
      memcpy(dp2, dp, sizeof dp2);
      for (int j = 0; j <= sm - i; j++)
        dp2[j + i] = (dp2[j + i] + MOD - dp2[j]) % MOD;
      for (int v = 0; v <= 500 * 500; v++)
        ok[v] = ok[v] && ((x(sm + v - i) + x(sm - v - i)) % MOD);
    }
    for (int v = 0; v <= 500 * 500; v++)
      if (ok[v])
        ans.push_back(v);
  }
  cout << ans.size() << endl;
  for (int i = 0; i < ans.size(); i++)
    cout << ans[i] << " \n"[i == ans.size() - 1];
}

Compilation message (stderr)

bootfall.cpp: In function 'int main()':
bootfall.cpp:39:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   for (int i = 0; i < ans.size(); i++)
      |                   ~~^~~~~~~~~~~~
bootfall.cpp:40:31: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |     cout << ans[i] << " \n"[i == ans.size() - 1];
      |                             ~~^~~~~~~~~~~~~~~~~
#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...