QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#203854 | #7567. Joining Cats | ucup-team2112# | WA | 531ms | 199248kb | C++20 | 2.3kb | 2023-10-06 21:11:50 | 2023-10-06 21:11:50 |
Judging History
answer
#include <bits/stdc++.h>
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int n, k;
std::cin >> n >> k;
std::vector<int> w(n), s(k);
for (auto &x : w) std::cin >> x;
for (auto &x : s) std::cin >> x;
std::vector gol(k, std::vector<short>(n));
std::vector gor(k, std::vector<short>(n));
std::vector pos(n, std::vector<short>(k));
for (int i = 0; i < n; i += 1) {
int last = -1;
for (int j = 0; j < k; j += 1) {
if (s[j] >= w[i]) {
last = j;
}
pos[i][j] = last;
}
}
for (int i = 0; i < k; i += 1) {
short nxt = 0;
long long sum = 0;
for (int j = 0; j < n; j += 1) {
if (nxt < j) {
nxt = j;
sum = 0;
}
while(nxt < n && sum + w[nxt] <= s[i]) {
sum += w[nxt];
nxt += 1;
}
gol[i][j] = std::min(nxt, (short)(n - 1));
sum -= w[j];
}
sum = 0;
nxt = n - 1;
for (int j = n - 1; j >= 0; j -= 1) {
if (nxt > j) {
nxt = j;
sum = 0;
}
while(nxt >= 0 && sum + w[nxt] <= s[i]) {
sum += w[nxt];
nxt -= 1;
}
gor[i][j] = std::max(nxt, (short)0);
sum -= w[j];
}
}
std::vector dp(n, std::vector<short>(n, -2));
dp[0][n - 1] = k - 1;
for (int len = n; len >= 2; len -= 1) {
for (int l = 0; l + len - 1 < n; l += 1) {
int r = l + len - 1;
if (dp[l][r] <= -1) continue;
short cur = dp[l][r];
int p = pos[l][cur];
// std::cerr << l << " " << r << " " << dp[l][r] << "\n";
if (p != -1) dp[std::min(short(r), gol[p][l])][r] = std::max(dp[std::min(short(r), gol[p][l])][r], short(cur - 1));
p = pos[r][cur];
if (p != -1) dp[l][std::max(short(l), gor[p][r])] = std::max(dp[l][std::max(short(l), gor[p][r])], short(cur - 1));
}
}
for (int i = 0; i < n; i += 1) {
if (dp[i][i] >= -1) {
std::cout << "Yes\n";
return 0;
}
}
std::cout << "No\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 3680kb
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: 3640kb
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: 3584kb
input:
5 1 5 4 3 2 1 10
output:
Yes
result:
ok answer is YES
Test #5:
score: 0
Accepted
time: 531ms
memory: 199248kb
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:
ok answer is NO
Test #6:
score: -100
Wrong Answer
time: 487ms
memory: 199148kb
input:
5000 5000 719129447 937392296 350445117 783330021 802155515 695380072 535475671 613171233 926763173 500405367 828284512 931492995 720877462 919465915 260912626 876806990 884762137 576596567 928561233 974405439 891740632 540536614 879167622 725668608 801467926 601260355 706621299 926987536 994204742 ...
output:
Yes
result:
wrong answer expected NO, found YES