QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#118221 | #6627. Line Town | platelet# | 0 | 0ms | 5604kb | C++17 | 1.4kb | 2023-07-03 11:08:21 | 2024-05-31 18:51:00 |
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], 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);
if(SZ(A) != SZ(B)) return inf;
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];
int ans = inf;
rep(k, 0, n) {
rep(i, 1, k) d[i] = i & 1 ? -1 : 1;
rep(i, k + 1, n) d[i] = i & 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: 0
Wrong Answer
time: 0ms
memory: 5588kb
input:
10 1 1 1 1 1 -1 -1 -1 1 -1
output:
1061109567
result:
wrong answer 1st numbers differ - expected: '-1', found: '1061109567'
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: 5604kb
input:
10 3 10 5 -9 7 2 -6 1 8 0
output:
1061109567
result:
wrong answer 1st numbers differ - expected: '-1', found: '1061109567'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%