#include <iostream> #include <map> #include <stdint.h> #include <vector> const int64_t P = 1'000'000'007; int g_result = 0; void print(const std::vector<int> &v) { for (int i : v) { std::cerr << i; } std::cerr << std::endl; } bool next(std::vector<int> &partitions, std::vector<int> &maxes, int n) { int i = 0; ++partitions[i]; while ((i < n - 1) && (partitions[i] > maxes[i] + 1)) { partitions[i] = 1; ++i; ++partitions[i]; } if (i == n - 1) { return false; } int max = partitions[i]; for (i = i - 1; i >= 0; --i) { maxes[i] = max; } return true; } void process(const std::vector<int64_t> &elements, const std::vector<int> &partition) { std::map<int, int64_t> m; for (size_t i = 0; i < elements.size(); ++i) { m[partition[i]] += elements[i]; } ///////////////////////////////// // std::cerr << "-------------------" << std::endl; // for (const auto &[k, v] : m) { // std::cerr << v << " "; // } // std::cerr << "\n-------------------" << std::endl; ///////////////////////////////// for (auto [k, v] : m) { if ((v % P) % 2 != 0) { // DEBUG // std::cerr << "quit" << std::endl; return; } } g_result++; } int main() { int N = 0; std::cin >> N; std::vector<int64_t> v(N); for (int i = 0; i < N; ++i) { std::cin >> v[i]; } ///////////////////// std::vector<int> partitions(N, 1); std::vector<int> maxes(N, 1); process(v, partitions); while (next(partitions, maxes, N) == true) { process(v, partitions); } std::cout << g_result << std::endl; return 0; }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 | #include <iostream> #include <map> #include <stdint.h> #include <vector> const int64_t P = 1'000'000'007; int g_result = 0; void print(const std::vector<int> &v) { for (int i : v) { std::cerr << i; } std::cerr << std::endl; } bool next(std::vector<int> &partitions, std::vector<int> &maxes, int n) { int i = 0; ++partitions[i]; while ((i < n - 1) && (partitions[i] > maxes[i] + 1)) { partitions[i] = 1; ++i; ++partitions[i]; } if (i == n - 1) { return false; } int max = partitions[i]; for (i = i - 1; i >= 0; --i) { maxes[i] = max; } return true; } void process(const std::vector<int64_t> &elements, const std::vector<int> &partition) { std::map<int, int64_t> m; for (size_t i = 0; i < elements.size(); ++i) { m[partition[i]] += elements[i]; } ///////////////////////////////// // std::cerr << "-------------------" << std::endl; // for (const auto &[k, v] : m) { // std::cerr << v << " "; // } // std::cerr << "\n-------------------" << std::endl; ///////////////////////////////// for (auto [k, v] : m) { if ((v % P) % 2 != 0) { // DEBUG // std::cerr << "quit" << std::endl; return; } } g_result++; } int main() { int N = 0; std::cin >> N; std::vector<int64_t> v(N); for (int i = 0; i < N; ++i) { std::cin >> v[i]; } ///////////////////// std::vector<int> partitions(N, 1); std::vector<int> maxes(N, 1); process(v, partitions); while (next(partitions, maxes, N) == true) { process(v, partitions); } std::cout << g_result << std::endl; return 0; } |