QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#226804 | #7567. Joining Cats | ucup-team2307# | ML | 8ms | 109032kb | C++14 | 1.7kb | 2023-10-26 16:40:44 | 2023-10-26 16:40:44 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define all(x) begin(x), end(x)
using ll = long long;
const int N = 5050;
int vis[N][N], nxt[N][N];
vector<ll> L[N], R[N];
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
vector<int> a(n), b(k);
for(auto &i : a) cin >> i;
for(auto &i : b) cin >> i;
memset(vis, -1, sizeof vis);
queue<array<int, 2>> q[N];
auto add = [&](int l, int r, int d) {
if(vis[l][r] == -1) {
vis[l][r] = d;
q[d].push({l, r});
} else {
assert(vis[l][r] <= d);
}
};
for(int i = 0; i < n; i++) {
nxt[i][k] = k;
for(int j = k;j--;) {
nxt[i][j] = b[j] >= a[i] ? j : nxt[i][j + 1];
}
}
for(int i = 0; i < n; i++) {
add(i, i, 0);
for(int j = i; j--;)
L[i].push_back((L[i].empty() ? 0 : L[i].back()) + a[j]);
for(int j = i + 1; j < n; j++)
R[i].push_back((R[i].empty() ? 0 : R[i].back()) + a[j]);
}
for(int D = 0; D < k; D++)
while(!q[D].empty()) {
auto [x, y] = q[D].front();
q[D].pop();
int d = vis[x][y];
if(d < k)
d = min(x ? nxt[x - 1][d] : k, y + 1 < n ? nxt[y + 1][d] : k);
if(d < k) {
int goL = upper_bound(all(L[x]), b[d]) - L[x].begin();
int goR = upper_bound(all(R[y]), b[d]) - R[y].begin();
// cout << x << " " << y << " " << goL << " " << goR << endl;
add(x - goL, y, d + 1);
add(x, y + goR, d + 1);
}
}
cout << (vis[0][n - 1] == -1 ? "No" : "Yes") << '\n';
}
详细
Test #1:
score: 100
Accepted
time: 4ms
memory: 109032kb
input:
5 2 1 1 1 1 1 2 2
output:
Yes
result:
ok answer is YES
Test #2:
score: 0
Accepted
time: 8ms
memory: 107892kb
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: 108908kb
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: 107196kb
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...