Submission #1237748


Source Code Expand

Copy
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=(n);i<(int)N;i++)
#define p(s) cout<<(s)<<endl
#define ck(n,a,b) (a)<=(n)&&(n)<(b)
typedef long long ll;
using namespace std;
const int inf=1e9;

int main(){
	int n;
	cin>>n;
	int a[100010];
	REP(i,0,n){
		cin>>a[i];
	}
	ll ans=0;
	ll sum=a[0];
	REP(i,1,n){
		ll tmp;
		tmp=sum;
		sum+=a[i];
		if(sum>=0&&tmp>0){
			ans+=sum+1;
			sum=-1;
		}else if(sum<=0&&tmp<0){

			ans+=-sum+1;
			sum=1;

		}
	}
	p(ans);
	return 0;
}

Submission Info

Submission Time
Task C - Sequence
User uwfdai
Language C++14 (GCC 5.4.1)
Score 0
Code Size 511 Byte
Status
Exec Time 56 ms
Memory 640 KB

Judge Result

Set Name Score / Max Score Test Cases
Sample 0 / 0 00-00.txt, 00-01.txt, 00-02.txt
All 0 / 300 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 1 ms 256 KB
00-01.txt 1 ms 256 KB
00-02.txt 1 ms 256 KB
01-00.txt 56 ms 640 KB
01-01.txt 56 ms 640 KB
01-02.txt 54 ms 640 KB
01-03.txt 52 ms 640 KB
01-04.txt 50 ms 640 KB
01-05.txt 44 ms 512 KB
01-06.txt 55 ms 640 KB
01-07.txt 48 ms 640 KB
01-08.txt 56 ms 640 KB
01-09.txt 49 ms 640 KB
01-10.txt 41 ms 512 KB
01-11.txt 54 ms 640 KB
01-12.txt 56 ms 640 KB
01-13.txt 49 ms 640 KB
01-14.txt 56 ms 640 KB