QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#516696 | #1281. Longest Common Subsequence | Z_drj | WA | 128ms | 7872kb | C++14 | 1.2kb | 2024-08-12 20:39:58 | 2024-08-12 20:40:00 |
Judging History
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(n), ra.push_back(n), lb.push_back(m), 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 = 0;
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[j]], sb[rb[j]] - sb[lb[j]]));
}
}
printf("%d\n", ans);
}
int main() {
int T; scanf("%d", &T);
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 7868kb
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: 128ms
memory: 7872kb
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:
0 0 1 5 2 1 0 1 2 1 1 1 1 4 1 0 1 1 0 2 4 4 1 1 1 0 2 1 4 6 4 1 1 4 2 1 1 1 2 1 1 1 3 0 1 2 4 1 1 4 0 2 1 2 2 1 4 0 1 2 2 1 1 4 4 2 2 0 1 0 3 5 2 2 1 1 2 3 0 1 2 0 5 1 4 2 1 3 3 2 6 0 0 3 1 4 1 2 0 3 1 6 3 2 0 1 0 4 3 4 0 2 0 0 1 4 2 3 0 3 0 5 1 1 2 1 0 0 0 2 0 1 3 2 2 2 3 3 4 0 1 2 2 1 1 1 4 4 2 1 ...
result:
wrong answer 1st words differ - expected: '1', found: '0'