답안 #22610

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
22610 2017-04-30T05:56:19 Z 카시코이(#958, xdoju, ntopia, pps789) Unifying Values (KRIII5_UV) C++
컴파일 오류
0 ms 0 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <unordered_map>
#include <algorithm>
using namespace std;

const int MOD = 1000000007;

int n;
long long arr[10004];
long long sum[10004];
long long allsum;

int d[2][10004];

int main() {
	//freopen("input.txt", "r", stdin);
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &arr[i]);
		sum[i] = sum[i - 1] + arr[i];
	}
	allsum = sum[n];

	unordered_map<long long, vector<int>> posbysum;
	for (int i = 0; i <= n; ++i) {
		posbysum[sum[i]];
		posbysum[sum[i]].push_back(i);
	}

	vector<int> cand;
	for (int i = 2; i <= n; ++i) {
		if (allsum % i == 0) {
			cand.push_back(i);
		}
	}

	long long ans = 0;

	if (allsum == 0) {
		long long targetsum = 0;

		vector<int> nxtp(n + 1);
		for (int j = 0; j < n; ++j) {
			long long sumi = sum[j] + targetsum;
			vector<int>& posv = posbysum[sumi];
			nxtp[j] = upper_bound(posv.begin(), posv.end(), j) - posv.begin();
		}

		d[0][0] = 1;
		for (int k = 1; k <= n; ++k) {
			memset(d[k % 2], 0, sizeof(d[k % 2]));
			for (int j = 0; j < n; ++j) {
				long long sumi = sum[j] + targetsum;
				vector<int>& posv = posbysum[sumi];
				auto it = posv.begin() + nxtp[j];
				while (it != posv.end()) {
					d[k % 2][*it] = (d[k % 2][*it] + d[1 - k % 2][j]) % MOD;
					++it;
				}
			}

			if (k >= 2) ans += d[k % 2][n];
		}
		printf("%d\n", ans % MOD);

		return 0;
	}

	for (int cnt : cand) {
		long long targetsum = allsum / cnt;

		vector<vector<int>> idxs(n + 1);
		vector<vector<int>> sum1(n + 1), prefix(n + 1);
		idxs[0].push_back(0);
		sum1[0].push_back(1);
		prefix[0].push_back(1);
		for (int k = 1; k <= cnt; ++k) {
			long long ss = targetsum * k;
			idxs[k] = posbysum[ss];
			sum1[k].assign(idxs[k].size(), 0);
			prefix[k].assign(idxs[k].size(), 0);

			int p = 0;
			for (int j = 0; j < idxs[k].size(); ++j) {
				while (p < idxs[k - 1].size() && idxs[k - 1][p] < idxs[k][j]) {
					++p;
				}
				sum1[k][j] = (p == 0) ? 0 : prefix[k - 1][p - 1];
				prefix[k][j] = (j == 0 ? 0 : prefix[k][j - 1]) + sum1[k][j];
				prefix[k][j] %= MOD;
			}
		}

		ans += prefix[cnt].back();
	}
	printf("%d\n", ans % MOD);

	return 0;
}

Compilation message

In file included from /usr/include/c++/5/unordered_map:35:0,
                 from UV.cpp:4:
/usr/include/c++/5/bits/c++0x_warning.h:32:2: error: #error This file requires compiler and library support for the ISO C++ 2011 standard. This support must be enabled with the -std=c++11 or -std=gnu++11 compiler options.
 #error This file requires compiler and library support \
  ^
UV.cpp: In function 'int main()':
UV.cpp:26:2: error: 'unordered_map' was not declared in this scope
  unordered_map<long long, vector<int>> posbysum;
  ^
UV.cpp:26:16: error: expected primary-expression before 'long'
  unordered_map<long long, vector<int>> posbysum;
                ^
UV.cpp:28:3: error: 'posbysum' was not declared in this scope
   posbysum[sum[i]];
   ^
UV.cpp:47:24: error: 'posbysum' was not declared in this scope
    vector<int>& posv = posbysum[sumi];
                        ^
UV.cpp:56:25: error: 'posbysum' was not declared in this scope
     vector<int>& posv = posbysum[sumi];
                         ^
UV.cpp:57:5: warning: 'auto' changes meaning in C++11; please remove it [-Wc++0x-compat]
     auto it = posv.begin() + nxtp[j];
     ^
UV.cpp:57:10: error: 'it' does not name a type
     auto it = posv.begin() + nxtp[j];
          ^
UV.cpp:58:12: error: 'it' was not declared in this scope
     while (it != posv.end()) {
            ^
UV.cpp:66:27: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
   printf("%d\n", ans % MOD);
                           ^
UV.cpp:71:17: warning: range-based 'for' loops only available with -std=c++11 or -std=gnu++11
  for (int cnt : cand) {
                 ^
UV.cpp:74:20: error: '>>' should be '> >' within a nested template argument list
   vector<vector<int>> idxs(n + 1);
                    ^
UV.cpp:75:20: error: '>>' should be '> >' within a nested template argument list
   vector<vector<int>> sum1(n + 1), prefix(n + 1);
                    ^
UV.cpp:81:14: error: 'posbysum' was not declared in this scope
    idxs[k] = posbysum[ss];
              ^
UV.cpp:86:22: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
    for (int j = 0; j < idxs[k].size(); ++j) {
                      ^
UV.cpp:87:14: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     while (p < idxs[k - 1].size() && idxs[k - 1][p] < idxs[k][j]) {
              ^
UV.cpp:98:26: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  printf("%d\n", ans % MOD);
                          ^
UV.cpp:19:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
UV.cpp:21:25: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%lld", &arr[i]);
                         ^