# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1119065 | lam280407 | Line Town (CCO23_day1problem3) | C++17 | 1 ms | 512 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){
int res = 0, sum = 0;
for (int j = 1; j <= i; ++j){
if (a[j] > 0) ++res;
else{
sum += res;
if (res & 1) break;
res = 0;
}
}
if (res & 1) continue;
sum += res;
res = 0;
for (int j = i + 1; j <= n; ++j){
if (a[j] < 0) ++res;
else{
sum += res;
if (res & 1) break;
res = 0;
}
}
if (res & 1) continue;
sum += res;
ans = min(ans, sum / 2);
}
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]);
}
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... |