답안 #436311

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436311 2021-06-24T12:16:02 Z keta_tsimakuridze Exam (eJOI20_exam) C++14
65 / 100
1000 ms 398504 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]==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 332 KB Output is correct
3 Correct 1 ms 300 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 13 ms 8332 KB Output is correct
2 Runtime error 685 ms 398504 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 11 ms 3380 KB Output is correct
3 Correct 53 ms 24288 KB Output is correct
4 Correct 194 ms 110132 KB Output is correct
5 Correct 209 ms 117980 KB Output is correct
6 Correct 235 ms 118032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 208 ms 118068 KB Output is correct
2 Execution timed out 1112 ms 318216 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 332 KB Output is correct
3 Correct 1 ms 300 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 676 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 1188 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 332 KB Output is correct
3 Correct 1 ms 300 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 2 ms 332 KB Output is correct
8 Correct 11 ms 3380 KB Output is correct
9 Correct 53 ms 24288 KB Output is correct
10 Correct 194 ms 110132 KB Output is correct
11 Correct 209 ms 117980 KB Output is correct
12 Correct 235 ms 118032 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 676 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 1188 KB Output is correct
20 Correct 2 ms 1228 KB Output is correct
21 Correct 3 ms 1184 KB Output is correct
22 Correct 14 ms 8316 KB Output is correct
23 Correct 645 ms 117588 KB Output is correct
24 Correct 363 ms 117544 KB Output is correct
25 Correct 276 ms 117568 KB Output is correct
26 Correct 273 ms 117516 KB Output is correct
27 Correct 255 ms 117484 KB Output is correct
28 Correct 221 ms 117872 KB Output is correct
29 Correct 215 ms 117768 KB Output is correct
30 Correct 251 ms 117848 KB Output is correct
31 Correct 212 ms 117768 KB Output is correct
32 Correct 212 ms 117828 KB Output is correct