QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118216 | #6627. Line Town | platelet# | 0 | 1ms | 5768kb | C++17 | 1.9kb | 2023-07-03 10:59:56 | 2024-05-31 18:50:47 |
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 = 1e6 + 8;
int n, h[N], d[N];
int solve() {
vector<int> A, B;
rep(i, 1, n) if(h[i] == 1) A.pb(i);
rep(i, 1, n) if(d[i] == 1) B.pb(i);
int res = 0;
For(i, 0, SZ(A)) res += abs(A[i] - B[i]);
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];
int cnt = 0;
rep(i, 1, n) cnt += h[i];
if(abs(cnt) > 1) cout << "-1\n", exit(0);
int ans = 1e9;
if(cnt == 0) {
rep(i, 1, n) d[i] = i & 1 ? -1 : 1;
cmin(ans, solve());
rep(i, 1, n) d[i] = ~i & 1 ? -1 : 1;
cmin(ans, solve());
}
if(cnt == 1) {
for(int k = 2; k < n; k += 2) {
rep(i, 1, k) d[i] = i & 1 ? -1 : 1;
rep(i, k + 1, n) d[i] = i - k & 1 ? 1 : -1;
cmin(ans, solve());
}
}
if(cnt == -1) {
for(int k = 1; k < n; k += 2) {
rep(i, 1, k) d[i] = i & 1 ? -1 : 1;
rep(i, k + 1, n) d[i] = i - k & 1 ? -1 : 1;
cmin(ans, solve());
}
}
cout << ans << '\n';
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 3
Accepted
time: 1ms
memory: 5560kb
input:
10 1 1 1 1 1 -1 -1 -1 1 -1
output:
-1
result:
ok 1 number(s): "-1"
Test #2:
score: 0
Accepted
time: 1ms
memory: 5768kb
input:
10 1 1 1 1 1 1 -1 1 1 -1
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: -3
Wrong Answer
time: 1ms
memory: 5632kb
input:
1 -1
output:
1000000000
result:
wrong answer 1st numbers differ - expected: '0', found: '1000000000'
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: 5628kb
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: 1ms
memory: 5612kb
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%