10119 | 2024-03-27 16:16:02 | 111 | Maximum felosztás | cpp17 | Time limit exceeded 25/100 | 1.1s | 521808 KiB |
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N,M;
cin>>N>>M;
vector<int>v(N+1),w(M+1);
for(int i=1;i<=N;i++){
cin>>v[i];
}
for(int i=1;i<=M;i++){
cin>>w[i];
}
vector<vector<int>>dp(M+1,vector<int>(N+1,0));
dp[0][0]=1;
for(int i=1;i<=M;i++){
int c=0;
for(int j=1;j<=N;j++){
int x=0;
for(int k=j;k>0;k--){
x=max(x,v[k]);
if(x==w[i]){
dp[i][j]+=dp[i-1][k-1];
dp[i][j]%=MOD;
}
}
c+=dp[i][j]!=dp[i][j-1];
}
if(c>count(v.begin(),v.end(),w[i])*2){
exit(1);
}
}
cout<<dp[M][N]<<'\n';
return 0;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Time limit exceeded | 1.1s | 9252 KiB | ||||
subtask2 | 10/10 | ||||||
3 | Accepted | 4ms | 2464 KiB | ||||
4 | Accepted | 4ms | 2448 KiB | ||||
5 | Accepted | 4ms | 2892 KiB | ||||
6 | Accepted | 4ms | 2884 KiB | ||||
7 | Accepted | 3ms | 2780 KiB | ||||
8 | Accepted | 3ms | 2952 KiB | ||||
subtask3 | 15/15 | ||||||
9 | Accepted | 52ms | 4488 KiB | ||||
10 | Accepted | 28ms | 4076 KiB | ||||
11 | Accepted | 28ms | 4056 KiB | ||||
12 | Accepted | 14ms | 3700 KiB | ||||
13 | Accepted | 8ms | 3472 KiB | ||||
14 | Accepted | 4ms | 3672 KiB | ||||
15 | Accepted | 90ms | 6736 KiB | ||||
16 | Accepted | 90ms | 6764 KiB | ||||
17 | Accepted | 39ms | 5176 KiB | ||||
18 | Accepted | 39ms | 5380 KiB | ||||
subtask4 | 0/15 | ||||||
19 | Time limit exceeded | 1.06s | 19240 KiB | ||||
20 | Time limit exceeded | 1.062s | 11412 KiB | ||||
21 | Accepted | 395ms | 7268 KiB | ||||
22 | Accepted | 48ms | 4492 KiB | ||||
23 | Accepted | 48ms | 4516 KiB | ||||
24 | Accepted | 29ms | 4756 KiB | ||||
25 | Time limit exceeded | 1.069s | 11752 KiB | ||||
26 | Time limit exceeded | 1.067s | 11944 KiB | ||||
27 | Time limit exceeded | 1.064s | 27548 KiB | ||||
28 | Time limit exceeded | 1.055s | 27628 KiB | ||||
29 | Accepted | 87ms | 5700 KiB | ||||
30 | Accepted | 87ms | 5824 KiB | ||||
31 | Accepted | 779ms | 11416 KiB | ||||
32 | Accepted | 781ms | 11428 KiB | ||||
33 | Time limit exceeded | 1.039s | 16324 KiB | ||||
34 | Time limit exceeded | 1.031s | 16328 KiB | ||||
35 | Time limit exceeded | 1.067s | 12572 KiB | ||||
36 | Time limit exceeded | 1.054s | 12704 KiB | ||||
37 | Accepted | 395ms | 8672 KiB | ||||
38 | Accepted | 397ms | 8704 KiB | ||||
subtask5 | 0/60 | ||||||
39 | Runtime error | 256ms | 521808 KiB | ||||
40 | Runtime error | 247ms | 521788 KiB | ||||
41 | Runtime error | 208ms | 521756 KiB | ||||
42 | Runtime error | 245ms | 521732 KiB | ||||
43 | Runtime error | 245ms | 521712 KiB | ||||
44 | Runtime error | 202ms | 521692 KiB | ||||
45 | Runtime error | 246ms | 521680 KiB | ||||
46 | Runtime error | 248ms | 521664 KiB | ||||
47 | Runtime error | 209ms | 521644 KiB | ||||
48 | Runtime error | 210ms | 521628 KiB | ||||
49 | Runtime error | 204ms | 521472 KiB | ||||
50 | Runtime error | 209ms | 521476 KiB | ||||
51 | Runtime error | 248ms | 521476 KiB | ||||
52 | Time limit exceeded | 1.059s | 86444 KiB | ||||
53 | Time limit exceeded | 1.085s | 48204 KiB | ||||
54 | Time limit exceeded | 1.08s | 49236 KiB | ||||
55 | Time limit exceeded | 1.05s | 18896 KiB | ||||
56 | Runtime error | 254ms | 521436 KiB | ||||
57 | Runtime error | 252ms | 521412 KiB | ||||
58 | Runtime error | 250ms | 521400 KiB | ||||
59 | Runtime error | 247ms | 521388 KiB | ||||
60 | Time limit exceeded | 1.065s | 86608 KiB | ||||
61 | Time limit exceeded | 1.049s | 87812 KiB | ||||
62 | Runtime error | 252ms | 521176 KiB | ||||
63 | Runtime error | 250ms | 521172 KiB | ||||
64 | Runtime error | 252ms | 521152 KiB | ||||
65 | Runtime error | 252ms | 521148 KiB | ||||
66 | Runtime error | 250ms | 521140 KiB | ||||
67 | Runtime error | 250ms | 521120 KiB | ||||
68 | Runtime error | 250ms | 521116 KiB | ||||
69 | Runtime error | 244ms | 521092 KiB | ||||
70 | Runtime error | 200ms | 521108 KiB | ||||
71 | Runtime error | 245ms | 521084 KiB |