QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#516723#1281. Longest Common SubsequenceZ_drjWA 124ms8160kbC++141.2kb2024-08-12 20:53:012024-08-12 20:53:01

Judging History

你现在查看的是最新测评结果

  • [2024-08-12 20:53:01]
  • 评测
  • 测评结果:WA
  • 用时:124ms
  • 内存:8160kb
  • [2024-08-12 20:53:01]
  • 提交

answer

#include <cstdio>
#include <vector>
#include <algorithm>

using i64 = long long;

const int N = 1e6 + 5;

int n, m;
int a[N], b[N];
int sa[N];
int sb[N];
void solve() {
	scanf("%d %d", &n, &m);

	for (int i = 1; i <= n; i++) {
		scanf("%d", a + i);
	}

	for (int i = 1; i <= m; i++) {
		scanf("%d", b + i);
	}

	std::vector<int> la, ra, lb, rb;
	la.push_back(0), ra.push_back(n), lb.push_back(0), rb.push_back(m);

	for (int i = 1; i <= n; i++) {
		if (a[i] == 1) {
			la.push_back(i);
		}
		sa[i] = sa[i - 1] + (a[i] == 2);
	}

	for (int i = n; i >= 1; i--) {
		if (a[i] == 3) {
			ra.push_back(i);
		}
	}

	for (int i = 1; i <= m; i++) {
		if (b[i] == 1) {
			lb.push_back(i);
		}
		sb[i] = sb[i - 1] + (b[i] == 2);
	}

	for (int i = m; i >= 1; i--) {
		if (b[i] == 3) {
			rb.push_back(i);
		}
	}
	
	int ans = std::min(sa[n], sb[m]);
	for (int i = 0; i < std::min((int)la.size(), (int)lb.size()); i++) {
		for (int j = 0; j < std::min((int)ra.size(), (int)rb.size()); j++) {
			ans = std::max(ans, i + j + std::min(sa[ra[j]] - sa[la[i]], sb[rb[j]] - sb[lb[i]]));
		}
	}

	printf("%d\n", ans);
}

int main() {
	int T; scanf("%d", &T);
	while (T--) {
		solve();
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 8160kb

input:

3
3 3
1 2 3
1 2 3
3 3
1 1 1
1 1 2
3 3
1 3 2
1 2 3

output:

3
2
2

result:

ok 3 tokens

Test #2:

score: -100
Wrong Answer
time: 124ms
memory: 7876kb

input:

139889
1 10
2
2 1 2 2 3 1 1 2 3 3
7 1
3 2 3 3 1 1 2
2
6 1
2 1 3 1 1 1
1
8 7
3 1 3 3 2 2 3 1
3 2 2 1 3 3 3
10 3
3 2 1 1 2 2 1 1 1 1
3 1 1
5 2
1 2 1 3 1
1 2
1 4
1
3 3 3 3
7 2
3 1 2 1 2 2 3
3 2
6 2
3 1 1 2 1 3
1 3
1 4
1
3 1 1 3
4 2
2 3 2 3
1 3
1 8
1
1 1 3 1 3 3 3 1
4 1
1 3 3 3
1
10 10
3 1 2 1 2 2 2 2 1...

output:

1
1
1
4
2
2
0
1
2
1
1
1
1
6
1
0
1
2
2
3
4
4
1
1
1
0
2
2
3
5
4
1
1
3
2
1
2
1
3
1
1
1
3
1
1
2
3
2
1
4
1
4
1
2
3
1
4
1
1
2
3
1
2
4
4
2
2
1
1
1
3
4
3
2
1
1
2
3
1
2
2
1
5
2
4
2
1
3
3
2
5
2
1
4
1
3
1
2
1
3
2
5
3
2
0
1
1
4
3
4
2
2
0
0
2
3
2
3
0
4
1
5
1
1
3
1
1
0
1
2
1
1
3
3
2
2
3
3
3
1
2
2
3
2
1
1
3
4
2
3
...

result:

wrong answer 30th words differ - expected: '4', found: '5'