Submission #166843

# Submission time Handle Problem Language Result Execution time Memory
166843 2019-12-04T10:11:53 Z anubhavdhar Nizin (COCI16_nizin) C++14
100 / 100
81 ms 10232 KB
#include<bits/stdc++.h>

#define ll long long int 
#define FOR(i,N) for(i=0;i<N;i++)
#define FORe(i,N) for(i=1;i<=N;i++)
#define FORr(i,a,b) for(i=a;i<b;i++)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define vi vector<ll>
#define ii pair<ll,ll>
#define vii vector<ii>

const ll MAXN = 1e5;
const ll LOGN = 17;
const ll ROOTN = 320;
const ll INF = 1e17+21;
const ll MOD = 1e9 + 7;

using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll N,i,a = 0,b = 0,c,d,l = 0,r = 0,ctr = 1;
	cin>>N;
	ll A[N];
	c = d = N-1;
	FOR(i,N)
		cin>>A[i];
	l = A[0];
	r = A[N-1];
	while(b < c)
	{
		//cout<<"entering for at ("<<a<<","<<b<<") and ("<<c<<","<<d<<")\n";
		if (l == r)
		{
			//cout<<"found palindrome at ("<<a<<","<<b<<") and ("<<c<<","<<d<<")\n";
			ctr += 2;
			if(b == c - 1) ctr--;
			b++;
			c--;
			a = b;
			d = c;
			l = A[b];
			r = A[c];
		}
		else if (l > r)
		{
			//cout<<"l>r\n";
			c--;
			r += A[c];
		}
		else
		{
			//cout<<"l<r\n";
			b++;
			l += A[b];
		}
		//cout<<"finally l = "<<l<<" and r = "<<r<<endl;
	}
	cout<<N - ctr;
	return 0;
}

Compilation message

nizin.cpp: In function 'int main()':
nizin.cpp:28:9: warning: variable 'a' set but not used [-Wunused-but-set-variable]
  ll N,i,a = 0,b = 0,c,d,l = 0,r = 0,ctr = 1;
         ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 504 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 380 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 8 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 1108 KB Output is correct
2 Correct 10 ms 1272 KB Output is correct
3 Correct 11 ms 1400 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 29 ms 3852 KB Output is correct
2 Correct 37 ms 4472 KB Output is correct
3 Correct 41 ms 5372 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 61 ms 7848 KB Output is correct
2 Correct 65 ms 8184 KB Output is correct
3 Correct 72 ms 9304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 79 ms 10028 KB Output is correct
2 Correct 81 ms 10140 KB Output is correct
3 Correct 80 ms 10232 KB Output is correct