답안 #436315

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436315 2021-06-24T12:21:10 Z keta_tsimakuridze Exam (eJOI20_exam) C++14
65 / 100
1000 ms 398084 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define int long long
using namespace std;
const int N=5000+5,mod=1e9+7;
int t,mx[N][N],b[N],a[N],dp[N],ans,n;
map<int,vector<int> > c;
bool ok(int x,int y) {
	if(mx[min(x,y)][max(x,y)] == a[x]) return 1;
	return 0;
}
 main(){
	cin>>n;

	for(int i=1;i<=n;i++) {
		cin >> a[i];
	}
	int f = 0;
	for(int i=1;i<=n;i++){
		cin >> b[i];
		if(i && b[i]!=b[i-1]) f = 1;
	}
	for(int i=1;i<=n;i++) {
		for(int j=i;j<=n;j++) {
			mx[i][j] = max(mx[i][j-1],a[j]);
		}
	}
	int ans = 0;
	if(!f) {
		
		for(int i=1;i<=n;i++){
			int j = i - 1,F = 0;
			while(j<n && a[j+1] <= b[1]) {
				j ++;
				if(b[1]==a[j]) F = 1;
			}
			if(F) ans += j - i + 1;
			i = max(i,j);
		}
		cout<<ans;
		return 0;
	}
	for(int i=1;i<=n;i++){
		c[a[i]].push_back(i);
	}
	for(int i=1;i<=n;i++) {
		for(int j=c[b[i]].size() - 1;j>=0;j--) {
			int ind = c[b[i]][j];
			dp[ind] = dp[ind] + ok(ind,i);
		}
		for(int j=1;j<=n;j++) {
			dp[j] = max(dp[j],dp[j-1]);
			ans = max(dp[j],ans);
			
		} //cout<<endl;
	}
	cout<<ans;
}

Compilation message

exam.cpp:13:2: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 |  main(){
      |  ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8328 KB Output is correct
2 Runtime error 702 ms 398084 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 5 ms 3276 KB Output is correct
3 Correct 40 ms 24268 KB Output is correct
4 Correct 202 ms 110084 KB Output is correct
5 Correct 225 ms 117932 KB Output is correct
6 Correct 217 ms 117872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 226 ms 117964 KB Output is correct
2 Execution timed out 1104 ms 398028 KB Time limit exceeded
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 460 KB Output is correct
9 Correct 1 ms 716 KB Output is correct
10 Correct 2 ms 1228 KB Output is correct
11 Correct 2 ms 1228 KB Output is correct
12 Correct 2 ms 1228 KB Output is correct
13 Correct 2 ms 1228 KB Output is correct
14 Correct 2 ms 1228 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 5 ms 3276 KB Output is correct
9 Correct 40 ms 24268 KB Output is correct
10 Correct 202 ms 110084 KB Output is correct
11 Correct 225 ms 117932 KB Output is correct
12 Correct 217 ms 117872 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 460 KB Output is correct
15 Correct 1 ms 716 KB Output is correct
16 Correct 2 ms 1228 KB Output is correct
17 Correct 2 ms 1228 KB Output is correct
18 Correct 2 ms 1228 KB Output is correct
19 Correct 2 ms 1228 KB Output is correct
20 Correct 2 ms 1228 KB Output is correct
21 Correct 2 ms 1228 KB Output is correct
22 Correct 13 ms 8344 KB Output is correct
23 Correct 659 ms 117492 KB Output is correct
24 Correct 373 ms 117376 KB Output is correct
25 Correct 307 ms 117452 KB Output is correct
26 Correct 215 ms 117456 KB Output is correct
27 Correct 262 ms 117460 KB Output is correct
28 Correct 210 ms 117764 KB Output is correct
29 Correct 219 ms 117748 KB Output is correct
30 Correct 212 ms 117828 KB Output is correct
31 Correct 205 ms 117952 KB Output is correct
32 Correct 214 ms 117700 KB Output is correct