Submission #9873629
Source Code Expand
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main(){ ll n; ll a[100010]; scanf("%lld",&n); for(int i = 0 ; i < n ; i ++){ scanf("%lld",&a[i]); } ll ret[2]; for(int t = 0 ; t < 2 ; t ++){ ll sum = 0; for(int i = 0 ; i < n ; i ++){ sum += a[i]; if((i&1) == t){ if(sum <= 0){ ret[t] += 1-sum; sum = 1; } } else { if(sum >= 0){ ret[t] += sum+1; sum = -1; } } } } cout << min( ret[0] , ret[1] ) << endl; }
Submission Info
Submission Time | |
---|---|
Task | C - Sequence |
User | shpsi |
Language | C++14 (GCC 5.4.1) |
Score | 300 |
Code Size | 534 Byte |
Status | AC |
Exec Time | 14 ms |
Memory | 1024 KB |
Compile Error
./Main.cpp: In function ‘int main()’: ./Main.cpp:9:18: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld",&n); ^ ./Main.cpp:11:22: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result] scanf("%lld",&a[i]); ^
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 KB |
00-01.txt | AC | 1 ms | 256 KB |
00-02.txt | AC | 1 ms | 256 KB |
01-00.txt | AC | 14 ms | 1024 KB |
01-01.txt | AC | 14 ms | 1024 KB |
01-02.txt | AC | 14 ms | 1024 KB |
01-03.txt | AC | 13 ms | 1024 KB |
01-04.txt | AC | 13 ms | 896 KB |
01-05.txt | AC | 12 ms | 896 KB |
01-06.txt | AC | 14 ms | 1024 KB |
01-07.txt | AC | 12 ms | 896 KB |
01-08.txt | AC | 14 ms | 1024 KB |
01-09.txt | AC | 13 ms | 896 KB |
01-10.txt | AC | 10 ms | 768 KB |
01-11.txt | AC | 14 ms | 1024 KB |
01-12.txt | AC | 14 ms | 1024 KB |
01-13.txt | AC | 13 ms | 896 KB |
01-14.txt | AC | 14 ms | 1024 KB |