QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#205214 | #7567. Joining Cats | ucup-team1479# | ML | 2ms | 13936kb | C++14 | 2.5kb | 2023-10-07 15:11:56 | 2023-10-07 15:11:56 |
Judging History
answer
#include <bits/stdc++.h>
#define file_in(x) (freopen(#x".in", "r", stdin))
#define file_out(x) (freopen(#x".out", "w", stdout))
#define file_ans(x) (freopen(#x".ans", "w", stdout))
#define int long long
#define vi vector
#define pr pair <int, int>
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define db double
using namespace std;
char _c; bool _f; template <class T> void IN(T &x) {
_f = x = 0; while (_c = getchar(), !isdigit(_c)) {if (_c == '-') _f = 1;}
while (isdigit(_c)) {x = x * 10 + _c - '0', _c = getchar();} if (_f) x = -x;
}
template <class T> void _write(T x) {
if (x < 0) return putchar('-'), _write(-x);
if (x > 9) _write(x / 10);
putchar('0' + x % 10);
}
template <class T> void write(T x) {_write(x), putchar('\n');}
template <class T> void write_s(T x) {_write(x), putchar(' ');}
template <class first, class... rest> void write(first fir, rest... res) {
write_s(fir), write(res...);
}
#define debug(...) (_debug(#__VA_ARGS__, __VA_ARGS__))
template <class T> void _debug(const char *format, T x) {
cerr << format << " = " << x << endl;
}
template <class first, class... rest>
void _debug(const char *format, first fir, rest... res) {
while (*format != ',') cerr << *format++;
cerr << " = " << fir << ",", _debug(format + 1, res...);
}
bool START;
const int N = 5e3 + 5, mod = 998244353;
int n, m, w[N], s[N], f[N][N], g[N][N], df[N][N], dg[N][N], pre[N];
pr e[N];
bool END;
signed main() {
IN(n), IN(m);
for (int i = 1; i <= n; ++i) IN(w[i]), pre[i] = pre[i - 1] + w[i];
for (int i = 1; i <= m; ++i) IN(s[i]), e[i] = mk(s[i], i);
sort(e + 1, e + 1 + m);
for (int i = 1; i <= n; ++i) {
for (int j = 1, k = i; j <= m; ++j) {
while (k < n && pre[k] - pre[i - 1] <= e[j].fi) k++;
df[i][e[j].se] = k;
}
}
for (int i = n; i; --i) {
for (int j = 1, k = i; j <= m; ++j) {
while (k > 1 && pre[i] - pre[k - 1] <= e[j].fi) k--;
dg[i][e[j].se] = k;
}
}
for (int i = 1; i <= n; ++i) f[i][1] = df[i][1], g[i][1] = dg[i][1];
for (int j = 2; j <= m; ++j) {
for (int i = 1, k = 1; i <= n; ++i) {
while (k < n && g[k + 1][j - 1] <= df[i][j]) k++;
f[i][j] = max(f[i][j - 1], max(k, f[df[i][j]][j - 1]));
}
for (int i = n, k = n; i; --i) {
while (k > 1 && f[k - 1][j - 1] >= dg[i][j]) k--;
g[i][j] = min(g[i][j - 1], min(k, g[dg[i][j]][j - 1]));
}
}
if (f[1][m] == n || g[n][m] == 1) puts("Yes");
else puts("No");
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9844kb
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: 11956kb
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: 2ms
memory: 13936kb
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: 11816kb
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