# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119056 | lam280407 | Line Town (CCO23_day1problem3) | C++17 | 2 ms | 340 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
#define vi vector<int>
#define pii pair<int, int>
#define fi first
#define se second
#define bit(n, i) ((n >> i) & 1)
#define inf 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(), (x).end()
#define el '\n'
#define TASK "bai3"
using namespace std;
const int N = 1e6 + 6;
int n, a[N];
namespace sub1{
int ans = inf;
void init(){
for (int i = 1; i <= n; ++i){
bool ok = true;
int res = 0, sum = 0;
for (int j = 1; j <= i; ++j){
if (!ok) break;
if (a[j] > 0) ++res;
else{
sum += res;
if (res & 1) ok = false;
res = 0;
}
}
sum += res;
if (res & 1) ok = false;
if (!ok) continue;
res = 0;
for (int j = i + 1; j <= n; ++j){
if (!ok) break;
if (a[j] < 0) ++res;
else{
sum += res;
if (res & 1) ok = false;
res = 0;
}
}
sum += res;
if (res & 1) ok = false;
if (!ok) continue;
ans = min(ans, sum >> 1);
}
cout << (ans == inf ? -1 : ans);
}
}
void solve(){
cin >> n;
int mn = inf, mx = -inf;
for (int i = 1; i <= n; ++i){
cin >> a[i];
mx = max(mx, a[i]);
mn = min(mn, a[i]);
}
if (n <= 2000 && mn == -1 && mx == 1) sub1::init();
}
void file(){
if (fopen(TASK".inp", "r")){
freopen(TASK".inp", "r", stdin);
freopen(TASK".out", "w", stdout);
}
}
signed main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
file();
solve();
}
Compilation message (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... |