Submission #2371721


Source Code Expand

#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<cstring>
#include<sstream>
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
	int n;
	cin >> n;

	long a[n];
	rep(i,0,n)
		cin >> a[i];

	long long rui = 0;
	long long ans = 0;
	int f; // -x => -1 , 0 => 0 , +x => 1

	rep(i,0,n){
		rui += a[i];
		
		if( i > 0 ){
			if( f == 0 ){
				if(rui > 0 )
					f = 1;
				else if( rui == 0){
					f = 0;
					ans += 2;
				}
				else 
					f = -1;
			}

			else if( rui >= 0 ){
				if(f == 1 ){
					ans += abs(rui-(-1));
					rui = -1;
					f = -1;
				}
				else{
					f = 1;
				}
			}
			else if( rui <= 0 ){
				if( f == -1){
					ans += abs(rui-1);
					rui = 1;
					f = 1;
				}
				else{
					f = -1;
				}
			}
			else if( rui == 0 ){
				if( f == 1 ){
					ans++;
					rui = -1;
				}
				else{
					ans++;
					rui = 1;
				}
			}

		}
		else{
			if( rui < 0 )
				f = -1;
			else if(rui == 0 ){
				f = 0;
				ans++;
			}
			else
				f = 1;
		}

	}

	if( rui == 0 )
		ans++;

	P(ans);
	ret 0;
}

Submission Info

Submission Time
Task C - Sequence
User walk_to_work
Language C++14 (GCC 5.4.1)
Score 0
Code Size 1833 Byte
Status WA
Exec Time 56 ms
Memory 1024 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 300
Status
AC × 3
AC × 7
WA × 11
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 WA 55 ms 1024 KB
01-01.txt WA 56 ms 1024 KB
01-02.txt WA 54 ms 1024 KB
01-03.txt WA 52 ms 1024 KB
01-04.txt WA 49 ms 896 KB
01-05.txt WA 44 ms 896 KB
01-06.txt WA 54 ms 1024 KB
01-07.txt AC 48 ms 896 KB
01-08.txt AC 56 ms 1024 KB
01-09.txt WA 49 ms 896 KB
01-10.txt WA 42 ms 768 KB
01-11.txt AC 54 ms 1024 KB
01-12.txt WA 55 ms 1024 KB
01-13.txt WA 50 ms 896 KB
01-14.txt AC 55 ms 1024 KB