QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#227426 | #7567. Joining Cats | salvator_noster# | WA | 19ms | 103620kb | C++20 | 1.9kb | 2023-10-27 15:30:36 | 2023-10-27 15:30:36 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 5000 + 5;
int N, M, w[MAX_N], s[MAX_N], f[MAX_N][MAX_N], maxv[MAX_N][MAX_N];
ll sum[MAX_N];
int bs1(int x, int r) {
int l = 0;
while (l < r) {
int mid = l + r + 1 >> 1;
if (maxv[mid][r] >= x) l = mid;
else r = mid - 1;
}
return l;
}
int bs2(int x, int l, int r) {
while (l < r) {
int mid = l + r + 1 >> 1;
if (sum[mid] - sum[l - 1] <= x) l = mid;
else r = mid - 1;
}
return l;
}
int bs3(int x, int l, int r) {
while (l < r) {
int mid = l + r >> 1;
if (sum[r] - sum[mid - 1] <= x) r = mid;
else l = mid + 1;
}
return l;
}
int main() {
scanf("%d%d", &N, &M);
for (int i = 1; i <= N; i ++) {
scanf("%d", w + i);
sum[i] = sum[i - 1] + w[i];
}
for (int i = 1; i <= M; i ++) {
scanf("%d", s + i);
maxv[i][i] = s[i];
}
for (int i = 1; i < N; i ++)
for (int j = i + 1; j <= N; j ++) maxv[i][j] = max(maxv[i][j - 1], s[i]);
f[1][N] = N + 1;
for (int i = N; i > 1; i --) {
for (int l = 1, r = l + i - 1; r <= N; l ++, r ++) {
if (f[l][r] < 1) continue;
int t = bs1(w[l], f[l][r] - 1), p;
if (t) {
p = bs2(s[t], l, r);
if (p >= r - 1) {
puts("Yes");
return 0;
}
f[p + 1][r] = max(f[p + 1][r], t);
}
t = bs1(w[r], f[l][r] - 1);
if (t) {
p = bs3(s[t], l, r);
if (p <= l + 1) {
puts("Yes");
return 0;
}
f[l][p - 1] = max(f[l][p - 1], t);
}
}
}
puts("No");
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5788kb
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: 5492kb
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: 5568kb
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: 5560kb
input:
5 1 5 4 3 2 1 10
output:
Yes
result:
ok answer is YES
Test #5:
score: 0
Accepted
time: 19ms
memory: 103000kb
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: 0
Accepted
time: 19ms
memory: 103320kb
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:
No
result:
ok answer is NO
Test #7:
score: 0
Accepted
time: 15ms
memory: 103620kb
input:
5000 5000 416747559 657602574 449451106 121890071 441124856 144632709 177533820 169507188 105623279 399624204 458468079 481561977 54065647 407303452 627276664 15195167 482406549 98222656 788603298 66301460 298650558 502696353 90244701 498415278 210561025 368288994 77615125 176971936 438514087 804772...
output:
No
result:
ok answer is NO
Test #8:
score: -100
Wrong Answer
time: 4ms
memory: 102532kb
input:
1000 5000 652378395 9226710 369514617 603608037 161741291 783580574 951641399 734721388 223516311 671669592 479702806 414081589 624003108 605424248 896097938 156346340 669596794 597103379 732027711 334398013 586620215 764336953 962550397 952888036 385377097 271706418 466047181 667473147 451787252 34...
output:
No
result:
wrong answer expected YES, found NO