QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#773806 | #9787. Shrek's Song of the Swamp | ucup-team2112# | WA | 0ms | 3664kb | C++20 | 1.0kb | 2024-11-23 10:23:58 | 2024-11-23 10:24:00 |
Judging History
answer
#include <bits/stdc++.h>
int main(){
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> a(n), nxt(n, n + 1);
for (int &x : a) std::cin >> x;
std::map<int, int> mp;
for (int i = n - 1; i >= 0; i -= 1) {
int x = a[i];
if (mp.contains(x)) {
nxt[i] = mp[x];
}
mp[x] = i;
}
int res = 0;
int last = int(1e9) + 10;
std::pair<int, int> mn = {1e9, 1e9};
for (int i = 0; i < n; i += 1) {
int x = a[i];
if (x == last) {
res += 1;
continue;
}
mn = std::min(mn, {nxt[i], i});
if (mn.first == i) {
int cnt = 0;
for (int j = mn.second + 1; j < mn.first; j += 1) {
cnt += a[j] == last;
}
res = std::max(res - cnt + 2, res);
mn = {1e9, 1e9};
continue;
}
}
std::cout << res << "\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 3664kb
input:
9 1 2 3 1 3 1 2 3 2
output:
4
result:
wrong answer 1st numbers differ - expected: '5', found: '4'