QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#773782 | #9787. Shrek's Song of the Swamp | ucup-team2112# | WA | 52ms | 10860kb | C++20 | 870b | 2024-11-23 10:19:32 | 2024-11-23 10:19:33 |
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;
int mn = 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]);
if (mn == i) {
last = x;
res += 2;
mn = 1e9;
continue;
}
}
std::cout << res << "\n";
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3616kb
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: 3620kb
input:
6 3 4 10 1 -3 5
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
4 1 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3616kb
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: 3852kb
input:
6 3 4 10 1 -3 5
output:
0
result:
ok 1 number(s): "0"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3848kb
input:
4 1 2 1 1
output:
3
result:
ok 1 number(s): "3"
Test #7:
score: -100
Wrong Answer
time: 52ms
memory: 10860kb
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:
504342
result:
wrong answer 1st numbers differ - expected: '463867', found: '504342'