Submission #40721

# Submission time Handle Problem Language Result Execution time Memory
40721 2018-02-07T09:32:50 Z ssnsarang2023 Boat (APIO16_boat) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;

#define SZ(x) ((int)x.size())

const int mod = (int)1e9+7;
const int N = 505;
int n, f[N], g[N], ftmp[N], gtmp[N], a[N], b[N], inv[N];
int choose[N][N], nCk[N]. nCk2[N], choose1[N][N], choose2[N][N];
vector<int> c, g[2*N];

int mul(int x, int y) {
	return (int)((ll)x * (ll)y % (ll)mod);
}

void add(int &x, int y) {
	x += y, x %= mod;
	if (x < 0) x += mod;
}

int fast_pw(int x, int y) {
	if (y == 1) return x % mod;
	if (y == 0) return 1;
	int t = fast_pw(x, y >> 1);
	t = mul(t, t);
	if (y & 1) t = mul(t, x);
	return t;
}

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; ++i) {
		scanf("%d%d", &a[i], &b[i]);
		c.push_back(a[i]);
		c.push_back(b[i]);
	}
	sort(c.begin(), c.end());
	c.resize(distance(c.begin(), unique(c.begin(), c.end())));
	for (int i = 0; i <= n; ++i) choose[i][i] = choose[i][0] = 1;
	inv[0] = 1;
	for (int i = 1; i <= n; ++i) {
		int lo = lower_bound(c.begin(), c.end(), a[i]) - c.begin();
		int hi = lower_bound(c.begin(), c.end(), b[i]) - c.begin();
		for (int j = lo; j <= hi; ++j) g[j].push_back(i);
		for (int j = 1; j < i; ++j) choose[i][j] = (choose[i - 1][j] + choose[i][j - 1]) % mod;
		inv[i] = mul(inv[i - 1], fast_pw(i, mod - 2));
	}
	for (int i = 0; i < SZ(c) - 1; ++i) {
		vector<int> tmp;
		for (int j = 0; j < SZ(g[i]); ++j) {
			if (b[g[i][j]] == c[i]) ftmp[g[i][j]] = gtmp[g[i][j]] = g[g[i][j] - 1];
			else tmp.push_back(g[i][j]);
		for (int j = 1; j <= n; ++j) add(gtmp[j], gtmp[j - 1]);
		int total = c[i + 1] - c[i], tmp_mul1 = 1, tmp_mul2 = 1;
		for (int j = 1; j <= min(total, SZ(tmp)); ++j) {
			tmp_mul1 = mul(tmp_mul1, total - j + 1);
			tmp_mul2 = mul(tmp_mul2, total - j);
			nCk[j] = mul(tmp_mul1, inv[j]);
			nCk2[j] = mul(tmp_mul2, inv[j]);
		}
		for (int j = 0; j <= min(total, SZ(tmp)) - 2; ++j) {
			for (int k = 0; k <= j; ++k) {
				choose1[i][j] = mul(choose[i][j], nCk[j + 2]);
				choose2[i][j] = mul(choose[i][j], nCk2[j + 2]);
				add(choose1[i][j], choose1[i][j - 1]);
				add(choose2[i][j], choose2[i][j - 1]);
			}
		}
		for (int j = SZ(tmp) - 1; j >= 0; --j) {
			int id = tmp[j];
			ftmp[id] = (f[tmp[id]] + mul(nCk[1], g[id - 1])) % mod;
			if (total > 1 && j > 0) {
				for (int k = j - 1; k >= 0; --k) {
					int mid = j - k - 1, id2 = tmp[k];
					add(ftmp[id], mul(g[id2 - 1], choose1[mid][min(mid, total - 2)]));
					if (total > 2) add(ftmp[id], mul(gtmp[id2 - 1], choose2[mid][min(mid, total - 3)]));
				}
			}
		}
		for (int i = 1; i <= n; ++i) {
			add(f[i], ftmp[i]);
			g[i] = (g[i - 1] + f[i]) % mod;
		}
	}
	printf("%lld", g[n]);
	return 0;
}

Compilation message

boat.cpp:14:25: error: expected initializer before '.' token
 int choose[N][N], nCk[N]. nCk2[N], choose1[N][N], choose2[N][N];
                         ^
boat.cpp:15:21: error: conflicting declaration 'std::vector<int> g [1010]'
 vector<int> c, g[2*N];
                     ^
boat.cpp:13:14: note: previous declaration as 'int g [505]'
 int n, f[N], g[N], ftmp[N], gtmp[N], a[N], b[N], inv[N];
              ^
boat.cpp: In function 'int main()':
boat.cpp:49:39: error: request for member 'push_back' in 'g[j]', which is of non-class type 'int'
   for (int j = lo; j <= hi; ++j) g[j].push_back(i);
                                       ^
boat.cpp:9:23: error: request for member 'size' in 'g[i]', which is of non-class type 'int'
 #define SZ(x) ((int)x.size())
                       ^
boat.cpp:55:23: note: in expansion of macro 'SZ'
   for (int j = 0; j < SZ(g[i]); ++j) {
                       ^
boat.cpp:56:16: error: invalid types 'int[int]' for array subscript
    if (b[g[i][j]] == c[i]) ftmp[g[i][j]] = gtmp[g[i][j]] = g[g[i][j] - 1];
                ^
boat.cpp:56:39: error: invalid types 'int[int]' for array subscript
    if (b[g[i][j]] == c[i]) ftmp[g[i][j]] = gtmp[g[i][j]] = g[g[i][j] - 1];
                                       ^
boat.cpp:56:55: error: invalid types 'int[int]' for array subscript
    if (b[g[i][j]] == c[i]) ftmp[g[i][j]] = gtmp[g[i][j]] = g[g[i][j] - 1];
                                                       ^
boat.cpp:56:68: error: invalid types 'int[int]' for array subscript
    if (b[g[i][j]] == c[i]) ftmp[g[i][j]] = gtmp[g[i][j]] = g[g[i][j] - 1];
                                                                    ^
boat.cpp:57:29: error: invalid types 'int[int]' for array subscript
    else tmp.push_back(g[i][j]);
                             ^
boat.cpp:63:4: error: 'nCk' was not declared in this scope
    nCk[j] = mul(tmp_mul1, inv[j]);
    ^
boat.cpp:64:4: error: 'nCk2' was not declared in this scope
    nCk2[j] = mul(tmp_mul2, inv[j]);
    ^
boat.cpp:68:5: error: 'choose1' was not declared in this scope
     choose1[i][j] = mul(choose[i][j], nCk[j + 2]);
     ^
boat.cpp:68:39: error: 'nCk' was not declared in this scope
     choose1[i][j] = mul(choose[i][j], nCk[j + 2]);
                                       ^
boat.cpp:69:5: error: 'choose2' was not declared in this scope
     choose2[i][j] = mul(choose[i][j], nCk2[j + 2]);
     ^
boat.cpp:69:39: error: 'nCk2' was not declared in this scope
     choose2[i][j] = mul(choose[i][j], nCk2[j + 2]);
                                       ^
boat.cpp:76:33: error: 'nCk' was not declared in this scope
    ftmp[id] = (f[tmp[id]] + mul(nCk[1], g[id - 1])) % mod;
                                 ^
boat.cpp:80:36: error: 'choose1' was not declared in this scope
      add(ftmp[id], mul(g[id2 - 1], choose1[mid][min(mid, total - 2)]));
                                    ^
boat.cpp:81:54: error: 'choose2' was not declared in this scope
      if (total > 2) add(ftmp[id], mul(gtmp[id2 - 1], choose2[mid][min(mid, total - 3)]));
                                                      ^
boat.cpp:90:21: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
  printf("%lld", g[n]);
                     ^
boat.cpp:92:1: error: expected '}' at end of input
 }
 ^
boat.cpp:36:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
                 ^
boat.cpp:38:30: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &a[i], &b[i]);
                              ^