QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#204528#7567. Joining Catsucup-team1631#WA 78ms3884kbC++142.0kb2023-10-07 12:56:202023-10-07 12:56:21

Judging History

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

  • [2023-10-07 12:56:21]
  • 评测
  • 测评结果:WA
  • 用时:78ms
  • 内存:3884kb
  • [2023-10-07 12:56:20]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, s, t) for (int i = (int)(s); i < (int)(t); ++i)
#define revrep(i, t, s) for (int i = (int)(t)-1; i >= (int)(s); --i)
#define all(x) begin(x), end(x)
template <typename T>
bool chmax(T& a, const T& b) {
    return a < b ? (a = b, 1) : 0;
}
template <typename T>
bool chmin(T& a, const T& b) {
    return a > b ? (a = b, 1) : 0;
}

template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    for (int i = 0; i < (int)v.size(); ++i) {
        os << v[i];
        if (i < (int)v.size() - 1) os << " ";
    }
    return os;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);

    int n, k;
    cin >> n >> k;
    vector<ll> w(n), s(k);
    for (auto& x : w) cin >> x;
    for (auto& x : s) cin >> x;

    vector<ll> cumsum(n + 1);
    rep(i, 0, n) cumsum[i + 1] = cumsum[i] + w[i];

    vector<int> min_right(n + 1, 1e9), max_left(n + 1, -1e9);
    min_right[0] = n;
    max_left[n] = 0;
    revrep(i, k, 0) {
        vector<int> new_min_right(n + 1, 1e9), new_max_left(n + 1, -1e9);
        rep(l, 0, n) {
            int r = min_right[l];
            if (r == 1e9) continue;
            int nl =
                upper_bound(all(cumsum), cumsum[l] + s[i]) - cumsum.begin();
            chmin(nl, r);
            chmin(new_min_right[nl], r);
            chmax(new_max_left[r], nl);
        }
        rep(r, 1, n + 1) {
            int l = max_left[r];
            if (l == -1e9) continue;
            int nr =
                lower_bound(all(cumsum), cumsum[r] - s[i]) - cumsum.begin();
            chmax(nr, l);
            chmax(new_max_left[nr], l);
            chmin(new_min_right[l], nr);
        }
        min_right.swap(new_min_right);
        max_left.swap(new_max_left);
    }
    rep(l, 0, n) {
        if (min_right[l] - l <= 1) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

详细

Test #1:

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

input:

5 2
1 1 1 1 1
2 2

output:

Yes

result:

ok answer is YES

Test #2:

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

input:

6 7
3 2 1 1 2 3
2 2 2 2 2 2 2

output:

No

result:

ok answer is NO

Test #3:

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

input:

7 4
1 2 3 4 3 2 1
3 3 3 3

output:

Yes

result:

ok answer is YES

Test #4:

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

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Wrong Answer
time: 78ms
memory: 3712kb

input:

5000 5000
775487425 856128884 277783434 903422359 477267301 475103384 297595527 426167697 732858986 408894759 274205836 78265305 841664344 827278645 235744961 539622829 661053351 709331224 497285040 688977639 794889854 890450616 730989757 164925481 519732355 5132018 793806705 617096813 966338860 838...

output:

Yes

result:

wrong answer expected NO, found YES