Codeforces Round #424 (Div. 2, rated, based on VK Cup finals) -831c jury Marks (thinking)

Source: Internet
Author: User

Test instructions: The player has an initial score, then a K-jury rating, which will be added to the player's score in turn, but the player remembers at some point in the process N (n<=k) a different score (in sequence), asking how many of the initial scores are possible.

Idea: Thinking problem +stl. First you can parse a K-score processing a prefix and find that the prefix and the same position in the two-moment fraction are the same, and then go through the unique function of the de-weight. You will then find the highlighted distinctin the topic, and the given N-known moment scores are different. So we have to construct an initial value to satisfy the existence of these n values, which can only be constructed from the number of CNT after the weight is removed. So enumerate the different prefixes of this CNT and, second-level enumeration n number, so as to determine an initial value, and then through the initial value to determine whether the third-level n number can pass the first CNT prefix and get.


Code:

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2005;
const int N = 8E6;
int A[MAXN], B[MAXN], PRE[MAXN];
int vis[2*n+5];
int k, n, base, ans, CNT, l;
Map<int, int> mp1;
int main ()
{
	scanf ("%d%d", &k, &n);
	for (int i = 1; I <= K; ++i) scanf ("%d", &a[i]);
	for (int i = 1; I <= n; ++i) scanf ("%d", &b[i]);
	Pre[0] = 0; Ans = 0;
	for (int i = 1; I <= K; ++i) pre[i] = Pre[i-1]+a[i];
	Sort (pre+1, pre+k+1);
	CNT = unique (pre+1, pre+k+1)-pre;
	for (int i = 1; i < cnt; ++i) ++mp1[pre[i];
	for (int i = 1, i < cnt; ++i)
	{for
		(int j = 1; j <= N; ++j)
		{
			base = B[j]-pre[i];
			if (Vis[base+n]) continue;	Each base value is incremented by one ans
			vis[base+n] = 1;
			for (L = 1; l <= N, ++l)
			{
				if (mp1.find (b[l]-base) = = Mp1.end ()) break;	Break small Optimization
			}
			if (l = = n+1) ++ans;}
	}
	printf ("%d\n", ans);
	return 0;
}

Continue to Refuel ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.