Please sign in first.
Submission #9233107
Source Code Expand
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 100100;
int N;
ll arr[MAXN];
ll res()
{
ll ctot = 0;
ll ans = 0;
for (int i = 0; i < N; i++)
{
ctot += arr[i];
if (i % 2 == 0)
{
if (ctot <= 0)
{
ans += 1 - ctot;
ctot = 1;
}
}
else
{
if (ctot >= 0)
{
ans += ctot + 1;
ctot = -1;
}
}
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(0);
cin >> N;
for (int i = 0; i < N; i++)
cin >> arr[i];
ll a = res();
for (int i = 0; i < N; i++)
arr[i] = -arr[i];
a = min (a, res());
cout << a << "\n";
}
Submission Info
| Submission Time | |
|---|---|
| Task | C - Sequence |
| User | scott_wu |
| Language | C++14 (GCC 5.4.1) |
| Score | 300 |
| Code Size | 845 Byte |
| Status | AC |
| Exec Time | 13 ms |
| Memory | 1024 KiB |
Judge Result
| Set Name | Sample | All | ||||
|---|---|---|---|---|---|---|
| Score / Max Score | 0 / 0 | 300 / 300 | ||||
| Status |
|
|
| Set Name | Test Cases |
|---|---|
| Sample | 00-00.txt, 00-01.txt, 00-02.txt |
| All | 00-00.txt, 00-01.txt, 00-02.txt, 01-00.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt |
| Case Name | Status | Exec Time | Memory |
|---|---|---|---|
| 00-00.txt | AC | 1 ms | 256 KiB |
| 00-01.txt | AC | 1 ms | 256 KiB |
| 00-02.txt | AC | 1 ms | 256 KiB |
| 01-00.txt | AC | 13 ms | 1024 KiB |
| 01-01.txt | AC | 13 ms | 1024 KiB |
| 01-02.txt | AC | 13 ms | 1024 KiB |
| 01-03.txt | AC | 12 ms | 1024 KiB |
| 01-04.txt | AC | 12 ms | 896 KiB |
| 01-05.txt | AC | 11 ms | 896 KiB |
| 01-06.txt | AC | 13 ms | 1024 KiB |
| 01-07.txt | AC | 12 ms | 896 KiB |
| 01-08.txt | AC | 13 ms | 1024 KiB |
| 01-09.txt | AC | 12 ms | 896 KiB |
| 01-10.txt | AC | 10 ms | 896 KiB |
| 01-11.txt | AC | 13 ms | 1024 KiB |
| 01-12.txt | AC | 13 ms | 1024 KiB |
| 01-13.txt | AC | 12 ms | 896 KiB |
| 01-14.txt | AC | 13 ms | 1024 KiB |