QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#204533 | #7567. Joining Cats | ucup-team1069# | ML | 1ms | 7780kb | C++23 | 1.7kb | 2023-10-07 12:59:59 | 2023-10-07 12:59:59 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N = 5100;
int n, k;
int w[N], s[N], dp[N][N];
int goR[N][N], goL[N][N];
int main() {
ios_base::sync_with_stdio(0), cin.tie(0);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> w[i];
}
for (int i = 1; i <= k; ++i) {
cin >> s[i];
}
reverse(s + 1, s + k + 1);
vector<pair<int, int>> v;
for (int i = 1; i <= k; ++i) {
v.push_back({s[i], i});
}
sort(v.begin(), v.end());
for (int i = 1; i <= n; ++i) {
int pos = i - 1;
long long W = 0;
for (auto [x, j] : v) {
while (pos + 1 <= n && W + w[pos + 1] <= x) {
pos++;
W += w[pos];
}
goR[i][j] = pos;
}
}
for (int i = 1; i <= n; ++i) {
int pos = i + 1;
long long W = 0;
for (auto [x, j] : v) {
while (pos - 1 >= 1 && W + w[pos - 1] <= x) {
pos--;
W += w[pos];
}
goL[i][j] = pos;
}
}
for (int i = 1; i <= k + 1; ++i) {
for (int j = 1; j <= n + 1; ++j) {
dp[i][j] = 1e9;
}
}
dp[1][1] = n;
for (int i = 1; i <= k; ++i) {
for (int j = 1; j <= n; ++j) {
if (dp[i][j] == 1e9) continue;
dp[i + 1][goR[j][i] + 1] = min(dp[i + 1][goR[j][i] + 1], dp[i][j]);
dp[i + 1][j] = min(dp[i + 1][j], goL[dp[i][j]][i] - 1);
}
}
for (int i = 1; i <= n; ++i) {
if (dp[k + 1][i] <= i) {
cout << "Yes\n";
return 0;
}
}
cout << "No\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 7780kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 1ms
memory: 7660kb
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: 1ms
memory: 7672kb
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: 1ms
memory: 7764kb
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