# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
1124487 | lmToT27 | Line Town (CCO23_day1problem3) | C++20 | 17 ms | 836 KiB |
#include <bits/stdc++.h>
#define all(dataStructure) dataStructure.begin(),dataStructure.end()
using namespace std;
typedef long long ll;
const int MAX = 1e5 + 3;
const int inf = 1e9;
const ll MOD[] = {1000000007, 998244353};
int n, h[MAX];
void Solve() {
cin >> n;
for (int i = 1; i <= n; i++) cin >> h[i];
int ans = inf;
for (int negaNums = 0; negaNums <= n; negaNums++) {
deque <int> t0, t1;
for (int i = 1; i <= n; i++) {
if (i & 1) {
if (h[i] == 1) t0.push_back(i);
else t1.push_back(i);
} else {
if (h[i] == -1) t0.push_back(i);
else t1.push_back(i);
}
}
int res = 0;
for (int i = 1; i <= negaNums; i++) {
auto &pos = (i & 1) ? t1 : t0;
if (pos.empty()) {
res = inf;
break;
}
res += max(0, pos.front() - i);
pos.pop_front();
}
for (int i = negaNums + 1; i <= n; i++) {
auto &pos = (i & 1) ? t0 : t1;
if (pos.empty()) {
res = inf;
break;
}
res += max(0, pos.front() - i);
pos.pop_front();
}
ans = min(ans, res);
}
cout << (ans == inf ? -1 : ans);
}
int32_t main() {
std::ios_base::sync_with_stdio(0);
std::cin.tie(0); std::cout.tie(0);
#define TASK ""
if (fopen(TASK".INP", "r")) {
freopen(TASK".INP", "r", stdin);
freopen(TASK".OUT", "w", stdout);
}
if (fopen("TASK.INP", "r")) {
freopen("TASK.INP", "r", stdin);
freopen("TASK.OUT", "w", stdout);
}
/* int TEST = 1; cin >> TEST; while (TEST--) */ Solve();
cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s\n";
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |