QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#117334 | #6627. Line Town | Qwerty1232# | 0 | 0ms | 3568kb | C++23 | 1.2kb | 2023-06-30 23:56:41 | 2024-05-31 18:44:32 |
Judging History
answer
#include <bits/stdc++.h>
int32_t main() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
int n;
std::cin >> n;
std::vector<int> input(n);
for (int i = 0; i < n; i++) {
std::cin >> input[i];
}
std::vector<int> prf(n + 1, -1), suf(n + 1, -1);
prf[0] = 0;
for (int i = 0; i < n; i++) {
if (input[i] == -1) {
prf[i + 1] = prf[i];
} else {
if (i >= 1 && input[i - 1] == input[i] && prf[i - 1] != -1) {
prf[i + 1] = prf[i - 1] + 1;
}
}
}
suf.rbegin()[0] = 0;
for (int i = 0; i < n; i++) {
if (input.rbegin()[i] == 1) {
suf.rbegin()[i + 1] = suf.rbegin()[i];
} else {
if (i >= 1 && input.rbegin()[i - 1] == input.rbegin()[i] && suf.rbegin()[i - 1] != -1) {
suf.rbegin()[i + 1] = suf.rbegin()[i - 1] + 1;
}
}
}
int ans = -1;
for (int i = 0; i <= n; i++) {
if (prf[i] != -1 && suf[i] != -1) {
if (ans == -1 || ans > prf[i] + suf[i]) {
ans = prf[i] + suf[i];
}
}
}
std::cout << ans << "\n";
return 0;
}
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 0ms
memory: 3464kb
input:
10 1 1 1 1 1 -1 -1 -1 1 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: -3
Wrong Answer
time: 0ms
memory: 3504kb
input:
10 1 1 1 1 1 1 -1 1 1 -1
output:
4
result:
wrong answer 1st numbers differ - expected: '3', found: '4'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Wrong Answer
Test #60:
score: 4
Accepted
time: 0ms
memory: 3568kb
input:
10 3 10 5 -9 7 2 -6 1 8 0
output:
-1
result:
ok 1 number(s): "-1"
Test #61:
score: -4
Wrong Answer
time: 0ms
memory: 3568kb
input:
10 -9 0 -1 7 5 10 6 3 2 -8
output:
-1
result:
wrong answer 1st numbers differ - expected: '13', found: '-1'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%