QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#516704 | #1281. Longest Common Subsequence | Z_drj | WA | 125ms | 7896kb | C++14 | 1.2kb | 2024-08-12 20:42:30 | 2024-08-12 20:42:30 |
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(0), ra.push_back(0), lb.push_back(0), rb.push_back(0);
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 7896kb
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: 125ms
memory: 7896kb
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 0 4 2 1 0 1 2 1 1 1 1 6 0 0 1 2 2 3 4 3 0 1 1 0 2 2 3 5 4 1 1 3 2 0 2 1 2 1 0 1 3 1 1 2 3 2 1 4 1 3 1 2 3 1 4 1 1 2 3 1 2 4 4 2 2 1 0 1 3 4 3 2 1 1 2 3 1 2 1 1 5 1 4 2 1 3 2 2 5 2 1 4 0 3 0 2 1 3 2 5 3 2 0 1 1 4 3 4 2 2 0 0 1 3 2 3 0 3 1 5 1 1 3 0 1 0 1 2 1 1 3 3 2 2 3 1 3 1 2 2 3 2 1 1 3 4 2 2 ...
result:
wrong answer 3rd words differ - expected: '1', found: '0'