101192024-03-27 16:16:02111Maximum felosztáscpp17Time limit exceeded 25/1001.1s521808 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;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Time limit exceeded1.1s9252 KiB
subtask210/10
3Accepted4ms2464 KiB
4Accepted4ms2448 KiB
5Accepted4ms2892 KiB
6Accepted4ms2884 KiB
7Accepted3ms2780 KiB
8Accepted3ms2952 KiB
subtask315/15
9Accepted52ms4488 KiB
10Accepted28ms4076 KiB
11Accepted28ms4056 KiB
12Accepted14ms3700 KiB
13Accepted8ms3472 KiB
14Accepted4ms3672 KiB
15Accepted90ms6736 KiB
16Accepted90ms6764 KiB
17Accepted39ms5176 KiB
18Accepted39ms5380 KiB
subtask40/15
19Time limit exceeded1.06s19240 KiB
20Time limit exceeded1.062s11412 KiB
21Accepted395ms7268 KiB
22Accepted48ms4492 KiB
23Accepted48ms4516 KiB
24Accepted29ms4756 KiB
25Time limit exceeded1.069s11752 KiB
26Time limit exceeded1.067s11944 KiB
27Time limit exceeded1.064s27548 KiB
28Time limit exceeded1.055s27628 KiB
29Accepted87ms5700 KiB
30Accepted87ms5824 KiB
31Accepted779ms11416 KiB
32Accepted781ms11428 KiB
33Time limit exceeded1.039s16324 KiB
34Time limit exceeded1.031s16328 KiB
35Time limit exceeded1.067s12572 KiB
36Time limit exceeded1.054s12704 KiB
37Accepted395ms8672 KiB
38Accepted397ms8704 KiB
subtask50/60
39Runtime error256ms521808 KiB
40Runtime error247ms521788 KiB
41Runtime error208ms521756 KiB
42Runtime error245ms521732 KiB
43Runtime error245ms521712 KiB
44Runtime error202ms521692 KiB
45Runtime error246ms521680 KiB
46Runtime error248ms521664 KiB
47Runtime error209ms521644 KiB
48Runtime error210ms521628 KiB
49Runtime error204ms521472 KiB
50Runtime error209ms521476 KiB
51Runtime error248ms521476 KiB
52Time limit exceeded1.059s86444 KiB
53Time limit exceeded1.085s48204 KiB
54Time limit exceeded1.08s49236 KiB
55Time limit exceeded1.05s18896 KiB
56Runtime error254ms521436 KiB
57Runtime error252ms521412 KiB
58Runtime error250ms521400 KiB
59Runtime error247ms521388 KiB
60Time limit exceeded1.065s86608 KiB
61Time limit exceeded1.049s87812 KiB
62Runtime error252ms521176 KiB
63Runtime error250ms521172 KiB
64Runtime error252ms521152 KiB
65Runtime error252ms521148 KiB
66Runtime error250ms521140 KiB
67Runtime error250ms521120 KiB
68Runtime error250ms521116 KiB
69Runtime error244ms521092 KiB
70Runtime error200ms521108 KiB
71Runtime error245ms521084 KiB