QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#205380 | #7567. Joining Cats | ucup-team045# | ML | 7ms | 108232kb | C++20 | 2.0kb | 2023-10-07 15:44:19 | 2023-10-07 15:44:19 |
Judging History
answer
#include<iostream>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
using LL = long long;
const int maxn = 5005;
vector<pair<int, int> > d[maxn];
int len1[maxn][maxn], len2[maxn][maxn];
int dp[maxn][maxn], w[maxn], s[maxn], id[maxn];
bool v[maxn][maxn];
int main(){
#ifdef LOCAL
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif
cin.tie(0);
cout.tie(0);
ios::sync_with_stdio(0);
int n, k;
cin >> n >> k;
for(int i = 1; i <= n; i++) cin >> w[i];
for(int i = 1; i <= k; i++)
cin >> s[i], id[i] = i;
sort(id + 1, id + k + 1, [&](int a, int b){
return s[a] < s[b];
});
for(int i = 1; i <= n; i++){
LL sum = 0;
for(int j = 1, pos = i - 1; j <= k; j++){
while(pos + 1 <= n && sum + w[pos + 1] <= s[id[j]]){
sum += w[++pos];
}
len1[i][id[j]] = pos - i + 1;
}
}
for(int i = 1; i <= n; i++){
LL sum = 0;
for(int j = 1, pos = i + 1; j <= k; j++){
while(pos - 1 >= 1 && sum + w[pos - 1] <= s[id[j]]){
sum += w[--pos];
}
len2[i][id[j]] = i - pos + 1;
}
}
memset(dp, 0x3f, sizeof dp);
dp[0][n + 1] = 0;
d[0].push_back({0, n + 1});
for(int i = 0; i < n; i++){
for(auto [x, y] : d[i]){
if (v[x][y]) continue;
v[x][y] = true;
int t1 = len1[x + 1][i + 1];
int t2 = len2[y - 1][i + 1];
if (x + t1 + 2 >= y || x + t2 + 2 >= y){
cout << "Yes" << '\n';
return 0;
}
if (i + 1 < dp[x + t1][y]){
dp[x + t1][y] = i + 1;
d[i + 1].push_back({x + t1, y});
}
if (i + 1 < dp[x][y - t2]){
dp[x][y - t2] = i + 1;
d[i + 1].push_back({x, y - t2});
}
}
}
cout << "No" << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 106240kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 7ms
memory: 108232kb
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: 3ms
memory: 106216kb
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: 4ms
memory: 106140kb
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