General
 
 
# Author Problem Lang Verdict Time Memory Sent Judged  
84285759 Practice:
JKLover
10D - 9 GNU C++17 Accepted 31 ms 2276 KB 2020-06-19 06:00:30 2020-06-19 06:00:30
 
 
→ Source
//%std
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int read()
{
	int out = 0, fh = 1;
	char jp = getchar();
	while ((jp > '9' || jp < '0') && jp != '-')
		jp = getchar();
	if (jp == '-')
		fh = -1, jp = getchar();
	while (jp >= '0' && jp <= '9')
		out = out * 10 + jp - '0', jp = getchar();
	return out * fh;
}
void print(int x)
{
	if (x >= 10)
		print(x / 10);
	putchar('0' + x % 10);
}
void write(int x, char c)
{
	if (x < 0)
		putchar('-'), x = -x;
	print(x);
	putchar(c);
}
const int N = 500 + 10;
int n, m, f[N][N], g[N][N], a[N], b[N];
void solve(int i, int j)
{
	if (!i)
		return;
	solve(i - 1, g[i][j]);
	if (g[i][j] != j)
		write(b[j], ' ');
}
int main()
{
	n = read();
	for (int i = 1; i <= n; ++i)
		a[i] = read();
	m = read();
	for (int i = 1; i <= m; ++i)
		b[i] = read();
	for (int i = 1; i <= n; ++i)
	{
		int k = 0;
		for (int j = 1; j <= m; ++j)
			if (a[i] == b[j])
			{
				f[i][j] = f[i - 1][k] + 1;
				g[i][j] = k;
			}
			else
			{
				f[i][j] = f[i - 1][j], g[i][j] = j;
				if (b[j] < a[i] && f[i - 1][j] > f[i - 1][k])
					k = j;
			}
	}
	int p = 0;
	for (int i = 1; i <= m; ++i)
		if (f[n][i] > f[n][p])
			p = i;
	write(f[n][p], '\n');
	if (f[n][p])
	{
		solve(n, p);
		puts("");
	}	
	return 0;
}
 
 
?
Time: ? ms, memory: ? KB
Verdict: ?
Input
?
Participant's output
?
Jury's answer
?
Checker comment
?
Diagnostics
?
Click to see test details