QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#723871#5475. Make a Loopemuach#WA 0ms3608kbC++201.7kb2024-11-08 01:59:552024-11-08 01:59:56

Judging History

你现在查看的是最新测评结果

  • [2024-11-08 01:59:56]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3608kb
  • [2024-11-08 01:59:55]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

namespace std {

template <int D, typename T>
struct Vec : public vector<Vec<D - 1, T>> {
    static_assert(D >= 1, "Dimension must be positive");
    template <typename... Args>
    Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) {}
};

template <typename T>
struct Vec<1, T> : public vector<T> {
    Vec(int n = 0, T val = T()) : std::vector<T>(n, val) {}
};

/* Example
    Vec<4, int64_t> f(n, k, 2, 2); // = f[n][k][2][2];
    Vec<2, int> adj(n); // graph
*/

template <class Fun>
class y_combinator_result {
    Fun fun_;

   public:
    template <class T>
    explicit y_combinator_result(T &&fun) : fun_(std::forward<T>(fun)) {}

    template <class... Args>
    decltype(auto) operator()(Args &&...args) {
        return fun_(std::ref(*this), std::forward<Args>(args)...);
    }
};

template <class Fun>
decltype(auto) y_combinator(Fun &&fun) {
    return y_combinator_result<std::decay_t<Fun>>(std::forward<Fun>(fun));
}

/* Example
    auto fun = y_combinator([&](auto self, int x) -> void {
        self(x + 1);
    });
*/

}  // namespace std

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    const int MAX = accumulate(a.begin(), a.end(), 0);
    if (MAX % 2) {
        cout << "No\n";
        return 0;
    }
    vector<int> cnt(MAX + 1);
    cnt[0] = 1;
    for (int i = 0; i < n; i++) {
        for (int j = MAX; j >= a[i]; j--) {
            cnt[j] += cnt[j - a[i]];
            if (cnt[j] > 2) cnt[j] = 2;
        }
    }
    cout << (cnt[MAX / 2] == 2 ? "Yes" : "No") << '\n';
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 3548kb

input:

4
1 1 1 1

output:

Yes

result:

ok single line: 'Yes'

Test #2:

score: 0
Accepted
time: 0ms
memory: 3520kb

input:

6
1 3 1 3 1 3

output:

Yes

result:

ok single line: 'Yes'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 3608kb

input:

6
2 2 1 1 1 1

output:

Yes

result:

wrong answer 1st lines differ - expected: 'No', found: 'Yes'