QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#138205 | #6627. Line Town | Cyanmond# | 0 | 0ms | 3600kb | C++17 | 1.9kb | 2023-08-11 09:13:52 | 2024-05-23 13:10:31 |
answer
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i, l, r) for (int i = (l); i < (r); ++i)
#define per(i, l, r) for (int i = (r - 1); i >= (l); --i)
#define ALL(x) (x).begin(), (x).end()
int main() {
int N;
cin >> N;
vector<int> H(N);
for (auto &e : H)
cin >> e;
if (all_of(ALL(H), [](int v) { return abs(v) == 1; })) {
vector<pair<int, int>> cp;
int last = 0;
rep (i, 0, N) {
if (H[i] != H[last]) {
cp.push_back({H[last], i - last});
last = i;
}
}
cp.push_back({H[last], N - last});
int l = 0, r = (int)cp.size();
rep (i, 0, (int)cp.size()) {
if (cp[i].second % 2 == 1 and cp[i].first == -1)
l = max(l, i);
if (cp[i].second % 2 == 1 and cp[i].first == 1)
r = min(r, i);
}
int cnt0l = 0, cnt0r = 0, cnt1l = 0, cnt1r = 0;
rep (i, 0, l + 1) {
if (cp[i].first == 1)
cnt0l += cp[i].second;
else
cnt1l += cp[i].second;
}
rep (i, l + 1, (int)cp.size()) {
if (cp[i].first == 1)
cnt0r += cp[i].second;
else
cnt1r += cp[i].second;
}
int ans = 1 << 30;
rep (i, l, r) {
ans = min(ans, cnt0l + cnt1r);
if (i != r - 1) {
if (cp[i + 1].first == 1) {
cnt0l += cp[i + 1].second;
cnt1l -= cp[i + 1].second;
} else if (cp[i + 1].first == -1) {
cnt0r += cp[i + 1].second;
cnt1r -= cp[i + 1].second;
}
}
}
if (ans == (1 << 30))
ans = -1;
cout << ans << endl;
}
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 0ms
memory: 3600kb
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: 3600kb
input:
10 1 1 1 1 1 1 -1 1 1 -1
output:
8
result:
wrong answer 1st numbers differ - expected: '3', found: '8'
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: 0
Wrong Answer
time: 0ms
memory: 3596kb
input:
10 3 10 5 -9 7 2 -6 1 8 0
output:
result:
wrong answer Answer contains longer sequence [length = 1], but output contains 0 elements
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%