QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#814060 | #9787. Shrek's Song of the Swamp | ucup-team4967# | WA | 119ms | 30500kb | C++23 | 929b | 2024-12-14 14:56:22 | 2024-12-14 14:56:29 |
Judging History
answer
#include <bits/extc++.h>
using ll = long long;
template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& xs) {
for (T& x : xs) is >> x;
return is;
}
int main() {
int N;
std::cin >> N;
std::vector<ll> S(N);
std::cin >> S;
std::vector<ll> zts = S;
std::sort(zts.begin(), zts.end());
zts.erase(std::unique(zts.begin(), zts.end()), zts.end());
int M = zts.size();
for (ll& x : S) {
x = std::lower_bound(zts.begin(), zts.end(), x) - zts.begin();
}
std::vector<int> back(N, -1);
{
std::vector<int> tmp(M, -1);
for (int i = 0; i < N; i++) {
back[i] = tmp[S[i]];
tmp[S[i]] = i;
}
}
std::vector<int> dp(N + 1, 0);
std::vector<int> dpsame(N, 0);
for (int i = 0; i < N; i++) {
int k = back[i];
if (k == -1) continue;
dpsame[i] = dp[k] + 2;
dp[i + 1] = std::max(dpsame[k] + 1, dpsame[i]);
}
std::cout << dp[N] << std::endl;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3564kb
input:
9 1 2 3 1 3 1 2 3 2
output:
5
result:
ok 1 number(s): "5"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
6 3 4 10 1 -3 5
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3460kb
input:
4 1 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3504kb
input:
9 1 2 3 1 3 1 2 3 2
output:
5
result:
ok 1 number(s): "5"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3724kb
input:
6 3 4 10 1 -3 5
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3528kb
input:
4 1 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: -100
Wrong Answer
time: 119ms
memory: 30500kb
input:
1000000 7 2 6 10 3 1 9 3 5 3 8 10 8 4 10 1 9 5 2 7 9 7 10 4 5 2 10 9 6 3 6 10 5 2 9 3 4 6 6 10 10 6 1 9 4 5 7 2 2 10 2 8 5 6 1 8 3 9 1 8 1 6 6 1 4 9 3 8 1 4 10 10 7 4 9 8 7 1 9 1 5 5 6 5 5 6 7 4 10 6 1 6 10 6 7 8 1 9 1 9 10 3 2 5 2 3 9 2 9 4 8 4 8 9 2 6 8 4 5 3 3 3 2 6 8 10 2 10 2 4 10 10 10 7 1 3 2...
output:
333037
result:
wrong answer 1st numbers differ - expected: '463867', found: '333037'