Submission #598435

# Submission time Handle Problem Language Result Execution time Memory
598435 2022-07-18T11:18:57 Z SuffixAutomata Bootfall (IZhO17_bootfall) C++17
13 / 100
4 ms 1236 KB
#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
int dp[500 * 500 + 1], dp2[500 * 500 + 1];
bool ok[1005];
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)
      return 0;
    return dp2[i / 2];
  };
  vector<int> ans;
  if (sm % 2 == 0 && dp[sm / 2]) {
    for (int v = 0; v <= 1000; 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 <= 1000; v++)
        ok[v] = ok[v] && ((x(sm + v - i) + x(sm - v - i)) % MOD);
    }
    for (int v = 0; v <= 1000; 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

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 time Memory Grader output
1 Correct 1 ms 1204 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 1204 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1212 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1204 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 1204 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1212 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1236 KB Output is correct
19 Correct 2 ms 1204 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1204 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 1204 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1212 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1236 KB Output is correct
19 Correct 2 ms 1204 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Incorrect 4 ms 1236 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1204 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 1204 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1212 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1236 KB Output is correct
19 Correct 2 ms 1204 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Incorrect 4 ms 1236 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1204 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 1204 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1212 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1236 KB Output is correct
19 Correct 2 ms 1204 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Incorrect 4 ms 1236 KB Output isn't correct
22 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 1204 KB Output is correct
2 Correct 1 ms 1236 KB Output is correct
3 Correct 0 ms 316 KB Output is correct
4 Correct 1 ms 1204 KB Output is correct
5 Correct 1 ms 1236 KB Output is correct
6 Correct 1 ms 1236 KB Output is correct
7 Correct 1 ms 1212 KB Output is correct
8 Correct 2 ms 1236 KB Output is correct
9 Correct 1 ms 1236 KB Output is correct
10 Correct 2 ms 1236 KB Output is correct
11 Correct 2 ms 1236 KB Output is correct
12 Correct 2 ms 1236 KB Output is correct
13 Correct 2 ms 1236 KB Output is correct
14 Correct 2 ms 1236 KB Output is correct
15 Correct 2 ms 1236 KB Output is correct
16 Correct 3 ms 1236 KB Output is correct
17 Correct 2 ms 1236 KB Output is correct
18 Correct 2 ms 1236 KB Output is correct
19 Correct 2 ms 1204 KB Output is correct
20 Correct 2 ms 1236 KB Output is correct
21 Incorrect 4 ms 1236 KB Output isn't correct
22 Halted 0 ms 0 KB -