Submission #832805

# Submission time Handle Problem Language Result Execution time Memory
832805 2023-08-21T15:45:45 Z caganyanmaz Boat (APIO16_boat) C++17
27 / 100
1073 ms 524288 KB
#include <bits/stdc++.h>
#define pb push_back
using namespace std;


//#define DEBUGGING
#ifdef DEBUGGING
#include "../debug.h"
#else
#define debug(x...) void(42)
#endif

constexpr static int MXN = 505;
constexpr static int MXR = 1005;
int n;
vector<int> a, b;
vector<int> ranges;
int dp[MXN][MXR][MXN]; // Schools passed, last range, count in  last range
int sums[MXN][MXN]; // last range
constexpr static int MOD = 1e9 + 7;

static inline int add(int a, int b) { return (a+b) % MOD; }
static inline int mul(int64_t a, int64_t b) { return (a*b) % MOD; }

int pow(int a, int b)
{
	int res = 1;
	while (b)
	{
		if (b&1)
		{
			res = mul(a, res);
			b--;
		}
		else
		{
			a = mul(a, a);
			b >>= 1;
		}
	}
	return res;
}

int _div(int a, int b) { return mul(a, pow(b, MOD-2)); }
int C[MXR][MXN];
int p[MXN];

int main()
{
	cin >> n;
	p[0] = 1;
	for (int i = 1; i < n; i++)
		p[i] = mul(i, p[i-1]);
	a.resize(n, 0), b.resize(n, 0);
	debug("A");
	for (int i = 0; i < n; i++)
	{
		cin >> a[i] >> b[i];
		b[i]++;
	}
	debug("b");
	vector<int> c;
 	for (int i = 0; i < n; i++)
		c.pb(a[i]);
	for (int i = 0; i < n; i++)
		c.pb(b[i]);
	debug("A");
	sort(c.begin(), c.end());
	auto last = unique(c.begin(), c.end());
	c.erase(last, c.end());
	int rn = c.size();
	for (int i = 0; i < c.size()-1; i++)
		ranges.pb(c[i+1] - c[i]);
	debug("B");
	for (int i = 0; i < rn; i++)
	{
		int pf = 1;
		for (int j = 0; j <= n; j++)
		{
			C[i][j] = pf;
			pf = mul(pf, ranges[i]-j);
			pf = _div(pf, j+1);
			if (ranges[i] < j)
				C[i][j] = 0;
			debug(i, j, C[i][j]);
		}
	}
	debug("D");
	debug(a, b);
	for (int& i : a)
		i = lower_bound(c.begin(), c.end(), i) - c.begin();
	for (int& i : b)
		i = lower_bound(c.begin(), c.end(), i) - c.begin();
	debug(a, b);
	for (int j = 0; j < rn; j++)
		dp[0][j][0] = 1;
	for (int i = 1; i <= n; i++) // Current node
	{
		for (int j = 0; j < rn; j++) // Current range
		{
			dp[i][j][0] = 1;
			for (int k = 1; k <= n; k++) // Current count 
			{
				if (a[i-1] <= j && b[i-1] > j)
				{
					if (j > 0 && k == 1)
						dp[i][j][k] = add(dp[i][j][k], sums[i-1][j-1]); // Starting with it
					dp[i][j][k] = add(dp[i][j][k], dp[i-1][j][k-1]); // Including it			
					debug(i, j, k);
				}
				dp[i][j][k] = add(dp[i][j][k], dp[i-1][j][k]); // Not including it
				debug(i, j, k, dp[i][j][k]);
			}
		}
		for (int j = 0; j < rn; j++)
		{
			if (j > 0)
				sums[i][j] = add(sums[i][j], sums[i][j-1]);
			debug(sums[i][j]);
			for (int k = 1; k <= n; k++)
			{
				sums[i][j] = add(sums[i][j], mul(dp[i][j][k], C[j][k]));
			}
			debug(i, j, sums[i][j]);
		}
	}
	int res = 0;
	for (int i = 0; i < rn; i++)
	{
		for (int j = 1; j <= n; j++)
		{
			debug(i, j, dp[n][i][j]);
			res = add(res, mul(dp[n][i][j], C[i][j]));
		}
	
	}
	cout << res << "\n";
}

Compilation message

boat.cpp: In function 'int main()':
boat.cpp:72:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   72 |  for (int i = 0; i < c.size()-1; i++)
      |                  ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1073 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1073 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 32 ms 41368 KB Output is correct
2 Correct 32 ms 41344 KB Output is correct
3 Correct 32 ms 41300 KB Output is correct
4 Correct 31 ms 41356 KB Output is correct
5 Correct 31 ms 41352 KB Output is correct
6 Correct 32 ms 41376 KB Output is correct
7 Correct 34 ms 41332 KB Output is correct
8 Correct 32 ms 41332 KB Output is correct
9 Correct 40 ms 41308 KB Output is correct
10 Correct 33 ms 41280 KB Output is correct
11 Correct 36 ms 41352 KB Output is correct
12 Correct 40 ms 41360 KB Output is correct
13 Correct 32 ms 41332 KB Output is correct
14 Correct 31 ms 41384 KB Output is correct
15 Correct 32 ms 41292 KB Output is correct
16 Correct 19 ms 24404 KB Output is correct
17 Correct 18 ms 23792 KB Output is correct
18 Correct 18 ms 23992 KB Output is correct
19 Correct 21 ms 24224 KB Output is correct
20 Correct 21 ms 23252 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1073 ms 524288 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -