Submission #22405

# Submission time Handle Problem Language Result Execution time Memory
22405 2017-04-30T04:26:20 Z past future present(#977, kazel, pjh0123, nemo) Unifying Values (KRIII5_UV) C++14
0 / 7
376 ms 2368 KB
#include<stdio.h>
#include<string.h>
#include<set>
#include<vector>
using namespace std;

const int mod = 1e9 + 7;

long long s[10000];
int n;

int modpow(long long a, long long b)
{
	return a*b%mod;
}

long long dp[10001];
vector<int> st;

long long cz(int i)
{
	if (i == n) return 1;
	if (dp[i] >= 0) return dp[i];
	dp[i] = 0;
	long long sum = 0;
	for (int j = i; j < n; j++)
	{
		sum += s[j];
		if (sum == 0)
		{
			dp[i] += cz(j + 1);
		}
	}
	dp[i] %= mod;
	return dp[i];
}

long long foo(int i)
{
	if (i == st.size()) return 1;
	if (dp[i] >= 0) return dp[i];
	dp[i] = 0;
	int sum = 0;
	for (int j = i; j < n; j++)
	{
		sum += st[j];
		if (sum == 1)
		{
			dp[i] = (dp[i] + foo(j + 1)) % mod;
		}
	}
	return dp[i];
}

set<long long> v;

int main()
{
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%lld", s + i);
	memset(dp, -1, sizeof(dp));
	long long sum = 0, ans = cz(0);
	for (int i = 0; i < n; i++) sum += s[i];
	if (sum == 0) ans--;
	sum = 0;
	v.insert(0);
	for (int b = 0; b < n - 1; b++)
	{
		sum += s[b];
		if (v.find(sum) != v.end()) continue;
		v.insert(sum);
		long long ts = 0;
		st.clear();
		int ncnt=0;
		for (int i = b + 1; i < n; i++)
		{
			ts += s[i];
			if (ts == sum)
			{
				st.push_back(1);
				ts = 0;
			}
			else if (ts == -sum)
			{
				st.push_back(-1);
				ts = 0;
			}
			else if (ts == 0)
			{
				st.push_back(0);
			}
		}
		if (ncnt == 0 && ts == 0)
		{
			memset(dp, -1, sizeof(dp));
			ans += foo(0);
		}
	}
	printf("%lld\n", ans%mod);
}

Compilation message

UV.cpp: In function 'long long int foo(int)':
UV.cpp:40:8: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  if (i == st.size()) return 1;
        ^
UV.cpp: In function 'int main()':
UV.cpp:59:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
UV.cpp:61:23: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", s + i);
                       ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 1332 KB Output is correct
2 Correct 0 ms 1332 KB Output is correct
3 Correct 0 ms 1332 KB Output is correct
4 Correct 239 ms 2368 KB Output is correct
5 Correct 276 ms 2368 KB Output is correct
6 Correct 153 ms 1676 KB Output is correct
7 Incorrect 236 ms 1512 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 376 ms 1508 KB Output isn't correct
2 Halted 0 ms 0 KB -