QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#118252 | #6627. Line Town | platelet# | 0 | 1ms | 7844kb | C++17 | 1.8kb | 2023-07-03 11:59:04 | 2024-05-31 18:51:41 |
Judging History
answer
#include <bits/stdc++.h>
#define rep(i, l, r) for(int i = (l); i <= (r); i++)
#define per(i, r, l) for(int i = (r); i >= (l); i--)
#define mem(a, b) memset(a, b, sizeof a)
#define For(i, l, r) for(int i = (l), i##e = (r); i < i##e; i++)
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define SZ(x) int((x).size())
using namespace std;
using ll = long long;
template<class T> inline T& cmin(T& a, const T& b) { if(b < a) a = b; return a; }
template<class T> inline T& cmax(T& a, const T& b) { if(a < b) a = b; return a; }
template<class... Args> void print(Args&&... args) {
((cout << args << ' '), ...);
}
template<class... Args> void println(Args&&... args) {
print(args...), cout << endl;
}
const int N = 5e5 + 8, inf = 0x3f3f3f3f;
int n, h[N];
pair<int, int> a[N];
ll dp[N][2];
ll init() {
ll res = 0;
rep(i, 1, n) {
auto [v, p] = a[i];
if(i & 1 ? v < 0 : v > 0) return inf;
For(j, 1, i) res += a[j].second > p;
}
return res;
}
int main() {
cin.tie(0)->sync_with_stdio(0);
cin >> n;
rep(i, 1, n) cin >> h[i];
for(int i = 2; i <= n; i += 2) h[i] = -h[i];
rep(i, 1, n) a[i] = {h[i], i};
sort(a + 1, a + n + 1, [](auto a, auto b) {
return abs(a.first) < abs(b.first);
});
ll ans = init();
rep(i, 1, n) {
auto [v, p] = a[i];
ll L = 0, R = 0;
For(j, 1, i) {
L += a[j].second < p;
R += a[j].second > p;
}
bool flag[2] = {v <= 0, v >= 0};
dp[i][0] = dp[i][1] = inf;
rep(j, 0, 1) {
if(flag[j]) cmin(dp[i][!j], dp[i - 1][j] + L);
if(flag[j ^ (i & 1)]) cmin(dp[i][j], dp[i - 1][j] + R);
}
}
cmin(ans, dp[n][1]);
cout << (ans == inf ? -1 : ans) << '\n';
}
详细
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 1ms
memory: 7768kb
input:
10 1 1 1 1 1 -1 -1 -1 1 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: 0
Wrong Answer
time: 1ms
memory: 7828kb
input:
10 1 1 1 1 1 1 -1 1 1 -1
output:
-1
result:
wrong answer 1st numbers differ - expected: '3', found: '-1'
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: 1ms
memory: 7844kb
input:
10 3 10 5 -9 7 2 -6 1 8 0
output:
-1
result:
ok 1 number(s): "-1"
Test #61:
score: 0
Wrong Answer
time: 1ms
memory: 7728kb
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%