QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#439487#7567. Joining CatspandapythonerML 0ms3816kbC++202.0kb2024-06-12 01:38:252024-06-12 01:38:25

Judging History

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

  • [2024-06-12 01:38:25]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:3816kb
  • [2024-06-12 01:38:25]
  • 提交

answer

#include <bits/stdc++.h>

#define short int
#define ull unsigned long long
#define ll long long
#define flt double
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()


using namespace std;

const ll inf = 1e18;
mt19937 rnd(234);


#ifdef LOCAL
bool local = true;
#else
bool local = false;
#endif




int32_t main() {
    if (1) {
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
    }
    int n, k;
    cin >> n >> k;
    vector<ll> w(n);
    vector<ll> s(k);
    for (int i = 0; i < n; i += 1) {
        cin >> w[i];
    }
    for (int i = 0; i < k; i += 1) {
        cin >> s[i];
    }
    vector<vector<short>> go_left(k, vector<short>(n + 1)), go_right(k, vector<short>(n + 1));
    for (int i = 0; i < k; i += 1) {
        int t = 0;
        ll sm = 0;
        for (int j = 0; j < n; j += 1) {
            while (sm > s[i]) {
                sm -= w[t];
                t += 1;
            }
            go_left[i][j] = t;
            sm += w[j];
        }
        t = n - 1;
        sm = 0;
        for (int j = n - 1; j >= 0; j -= 1) {
            while (sm > s[i]) {
                sm -= w[t];
                t -= 1;
            }
            go_right[i][j] = t;
            sm += w[j];
        }
    }
    vector<vector<short>> dp(n + 1, vector<short>(n + 1, k + 1));
    for (int i = 0; i < n; i += 1) {
        dp[i][i] = 0;
    }
    for (int len = 1; len <= n; len += 1) {
        for (int l = 0; l + len - 1 < n; l += 1) {
            int r = l + len - 1;
            int x = dp[l][r];
            if (x < k) {
                dp[go_left[x][l]][r] = min<short>(dp[go_left[x][l]][r], x + 1);
                dp[l][go_right[x][r]] = min<short>(dp[l][go_right[x][r]], x + 1);
            }
        }
    }
    if (dp[0][n - 1] <= k) {
        cout << "Yes" << "\n";
    } else {
        cout << "No" << "\n";
    }
    return 0;
}


/*
6 7
3 2 1 1 2 3
2 2 2 2 2 2 2

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

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3532kb

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: 3604kb

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: 3816kb

input:

5 1
5 4 3 2 1
10

output:

Yes

result:

ok answer is YES

Test #5:

score: -100
Memory Limit Exceeded

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:

No

result: