Submission #588449

# Submission time Handle Problem Language Result Execution time Memory
588449 2022-07-03T09:58:12 Z dozer Exam (eJOI20_exam) C++14
13 / 100
345 ms 197584 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define sp " "
#define endl "\n"
#define fileio() freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout)
#define fastio() cin.tie(0), ios_base::sync_with_stdio(0)
#define N 5005
#define pii pair<int, int>
#define st first
#define nd second
#define modulo 1000000007
#define LOGN 18
#define int long long


int a[N], b[N];
int dp[N][N];
map<int, int> val;


int f(int i, int j)
{
	if (i == 0 || j == 0) return 0;
	if (dp[i][j] != -1) return dp[i][j];
	int ans = f(i, j - 1);
	if (b[j] == a[i]) ans++;
	ans = max(ans, f(i - 1, min(j, i - 1)));
	return dp[i][j] = ans;
}

int32_t main()
{
	fastio();

	memset(dp, -1, sizeof(dp));
	int n;
	cin>>n;
	set<int> s;
	for (int i = 1; i <= n; i++)
	{
		cin>>a[i];
		s.insert(a[i]);
	}
	int cntr = 1;
	for (auto i : s)
	{
		val[i] = cntr;
		cntr++;
	}
	for (int i = 1; i <= n; i++)
		a[i] = val[a[i]];

	for (int i = 1; i <= n; i++)
	{
		cin>>b[i];
		b[i] = val[b[i]];
	}
	
	cout<<f(n, n)<<endl;
	cerr<<"time taken : "<<(float)clock() / CLOCKS_PER_SEC<<" seconds\n";
}
# Verdict Execution time Memory Grader output
1 Correct 73 ms 196428 KB Output is correct
2 Correct 71 ms 196420 KB Output is correct
3 Correct 72 ms 196384 KB Output is correct
4 Correct 69 ms 196280 KB Output is correct
5 Incorrect 77 ms 196396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 81 ms 196564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 74 ms 196352 KB Output is correct
2 Correct 77 ms 196424 KB Output is correct
3 Correct 111 ms 196792 KB Output is correct
4 Correct 260 ms 197492 KB Output is correct
5 Correct 331 ms 197560 KB Output is correct
6 Correct 345 ms 197532 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 275 ms 197584 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 196428 KB Output is correct
2 Correct 71 ms 196420 KB Output is correct
3 Correct 72 ms 196384 KB Output is correct
4 Correct 69 ms 196280 KB Output is correct
5 Incorrect 77 ms 196396 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 73 ms 196428 KB Output is correct
2 Correct 71 ms 196420 KB Output is correct
3 Correct 72 ms 196384 KB Output is correct
4 Correct 69 ms 196280 KB Output is correct
5 Incorrect 77 ms 196396 KB Output isn't correct
6 Halted 0 ms 0 KB -