QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#516699 | #1281. Longest Common Subsequence | Z_drj | WA | 128ms | 8124kb | C++14 | 1.2kb | 2024-08-12 20:40:54 | 2024-08-12 20:40:55 |
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 = 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[j]], sb[rb[j]] - sb[lb[j]]));
}
}
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: 1ms
memory: 7892kb
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: 8124kb
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 5 2 1 0 1 2 1 1 1 1 5 1 0 1 1 2 2 4 4 1 1 1 0 2 2 4 6 4 1 1 4 2 1 1 1 2 1 1 1 3 1 1 2 4 2 1 4 1 3 1 2 2 1 4 1 1 2 2 1 2 4 4 2 2 1 1 1 3 5 2 2 1 1 2 3 0 2 2 1 5 1 4 2 1 3 3 2 6 2 1 3 1 4 1 2 1 3 2 6 3 2 0 1 1 4 3 4 2 2 0 0 1 4 2 3 0 3 1 5 1 1 2 1 1 0 1 2 1 1 3 2 2 2 3 3 4 1 2 2 3 2 1 1 4 4 2 2 ...
result:
wrong answer 4th words differ - expected: '4', found: '5'