1285 | 2022-03-30 09:41:50 | Valaki2 | Maximum felosztás | cpp14 | Runtime error 40/100 | 1.077s | 497700 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
const int mod = 1e9 + 7;
const int maxn = 1e5;
void solve() {
int n, m;
cin >> n >> m;
// mistaking n, m ?
vector<int> a(1 + n, 0);
vector<int> b(1 + m, 0);
vector<int> v(1, 0);
for(int i = 1; i <= n; i++) {
cin >> a[i];
v.pb(a[i]);
}
for(int i = 1; i <= m; i++) {
cin >> b[i];
v.pb(b[i]);
}
sort(v.begin(), v.end());
v.resize(unique(v.begin(), v.end()) - v.begin());
for(int i = 1; i <= n; i++) {
a[i] = (int) (lower_bound(v.begin(), v.end(), a[i]) - v.begin());
}
for(int i = 1; i <= m; i++) {
b[i] = (int) (lower_bound(v.begin(), v.end(), b[i]) - v.begin());
}
// all elements between 1 and n+m<=2e5
/*for(int i = 1; i <= n; i++) {
cout << a[i] << " ";
}
cout << "\n";
for(int i = 1; i <= m; i++) {
cout << b[i] << " ";
}
cout << "\n";*/
vector<vector<pair<int, int> > > intervals(1 + 2 * maxn);
for(int l = 1; l <= n; l++) {
int maxi = 0;
for(int r = l; r <= n; r++) {
maxi = max(maxi, a[r]);
intervals[maxi].pb(mp(l, r));
}
}
vector<int> dp;
dp.assign(1 + n, 0);
dp[0] = 1;
for(int i = 1; i <= m; i++) {
vector<int> new_dp(1 + n, 0);
for(pair<int, int> p : intervals[b[i]]) {
new_dp[p.se] = (new_dp[p.se] + dp[p.fi - 1]) % mod;
}
dp = new_dp;
}
cout << dp[n] << "\n";
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
solve();
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 7ms | 11000 KiB | ||||
2 | Accepted | 81ms | 83348 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 9ms | 16204 KiB | ||||
4 | Accepted | 9ms | 15832 KiB | ||||
5 | Accepted | 9ms | 15984 KiB | ||||
6 | Accepted | 8ms | 15716 KiB | ||||
7 | Accepted | 9ms | 15708 KiB | ||||
8 | Accepted | 8ms | 15584 KiB | ||||
subtask3 | 15/15 | ||||||
9 | Accepted | 9ms | 16412 KiB | ||||
10 | Accepted | 8ms | 15604 KiB | ||||
11 | Accepted | 10ms | 15996 KiB | ||||
12 | Accepted | 10ms | 16136 KiB | ||||
13 | Accepted | 10ms | 15688 KiB | ||||
14 | Accepted | 8ms | 15776 KiB | ||||
15 | Accepted | 10ms | 16792 KiB | ||||
16 | Accepted | 8ms | 16488 KiB | ||||
17 | Accepted | 9ms | 16628 KiB | ||||
18 | Accepted | 8ms | 16324 KiB | ||||
subtask4 | 15/15 | ||||||
19 | Accepted | 90ms | 91648 KiB | ||||
20 | Accepted | 85ms | 109772 KiB | ||||
21 | Accepted | 75ms | 96996 KiB | ||||
22 | Accepted | 82ms | 96804 KiB | ||||
23 | Accepted | 101ms | 101692 KiB | ||||
24 | Accepted | 79ms | 84900 KiB | ||||
25 | Accepted | 68ms | 86732 KiB | ||||
26 | Accepted | 65ms | 80580 KiB | ||||
27 | Accepted | 59ms | 88708 KiB | ||||
28 | Accepted | 150ms | 91596 KiB | ||||
29 | Accepted | 57ms | 77388 KiB | ||||
30 | Accepted | 82ms | 83288 KiB | ||||
31 | Accepted | 54ms | 80664 KiB | ||||
32 | Accepted | 98ms | 87832 KiB | ||||
33 | Accepted | 59ms | 82560 KiB | ||||
34 | Accepted | 107ms | 89896 KiB | ||||
35 | Accepted | 54ms | 84088 KiB | ||||
36 | Accepted | 116ms | 90992 KiB | ||||
37 | Accepted | 57ms | 80388 KiB | ||||
38 | Accepted | 86ms | 89392 KiB | ||||
subtask5 | 0/60 | ||||||
39 | Runtime error | 426ms | 322032 KiB | ||||
40 | Runtime error | 414ms | 384804 KiB | ||||
41 | Time limit exceeded | 367ms | 190440 KiB | ||||
42 | Time limit exceeded | 458ms | 208360 KiB | ||||
43 | Runtime error | 298ms | 333632 KiB | ||||
44 | Time limit exceeded | 363ms | 178048 KiB | ||||
45 | Runtime error | 363ms | 330372 KiB | ||||
46 | Runtime error | 337ms | 319856 KiB | ||||
47 | Time limit exceeded | 446ms | 215864 KiB | ||||
48 | Time limit exceeded | 449ms | 198900 KiB | ||||
49 | Runtime error | 340ms | 340616 KiB | ||||
50 | Runtime error | 314ms | 298048 KiB | ||||
51 | Time limit exceeded | 400ms | 204028 KiB | ||||
52 | Time limit exceeded | 437ms | 209568 KiB | ||||
53 | Time limit exceeded | 402ms | 201276 KiB | ||||
54 | Runtime error | 375ms | 449204 KiB | ||||
55 | Time limit exceeded | 354ms | 201144 KiB | ||||
56 | Time limit exceeded | 518ms | 224656 KiB | ||||
57 | Time limit exceeded | 411ms | 223912 KiB | ||||
58 | Time limit exceeded | 375ms | 205136 KiB | ||||
59 | Time limit exceeded | 1.026s | 198588 KiB | ||||
60 | Runtime error | 282ms | 278040 KiB | ||||
61 | Time limit exceeded | 398ms | 230896 KiB | ||||
62 | Runtime error | 294ms | 398780 KiB | ||||
63 | Runtime error | 898ms | 497556 KiB | ||||
64 | Time limit exceeded | 293ms | 213064 KiB | ||||
65 | Runtime error | 917ms | 497700 KiB | ||||
66 | Runtime error | 312ms | 407020 KiB | ||||
67 | Time limit exceeded | 1.047s | 216184 KiB | ||||
68 | Runtime error | 314ms | 393484 KiB | ||||
69 | Time limit exceeded | 1.077s | 228940 KiB | ||||
70 | Runtime error | 356ms | 328544 KiB | ||||
71 | Time limit exceeded | 819ms | 231040 KiB |