Submission #591136

# Submission time Handle Problem Language Result Execution time Memory
591136 2022-07-06T22:15:21 Z blue Kangaroo (CEOI16_kangaroo) C++17
0 / 100
0 ms 212 KB
#include <iostream>
#include <vector>
using namespace std;

using ll = long long;
const ll mod = 1'000'000'007LL;


ll ad(ll a, ll b)
{
	return (a+b)%mod;
}

ll mul(ll a, ll b)
{
	return (a*b)%mod;
}

void selfadd(int& a, int b)
{
	a = ad(a, b);
}


int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int N, cs, cf;
	cin >> N >> cs >> cf;

	if(cs > cf)
		swap(cs, cf);

	int DP[1+N][2+N];

	DP[0][1] = 1;

	for(int i = 1; i <= N; i++)
	{
		for(int j = 0; j <= 1+i; j++)
		{
			DP[i][j] = 0;
			
			if(i == cs || i == cf)
			{
				selfadd(DP[i][j], DP[i-1][j]);
				if(j+1 <= N+1)
					selfadd(DP[i][j], DP[i-1][j+1]);
			}
			else
			{
				if(j >= 1)
					selfadd(DP[i][j], mul(j-1, DP[i-1][j-1]));

				if(j+1 <= N+1 && j+1 - (i < cs) - (i < cf) >= 0)
					selfadd(DP[i][j], mul(j+1 - (i < cs) - (i < cf), DP[i-1][j+1]));
			}

			// cerr << i << ' ' << j << " : " << DP[i][j] << '\n';
		}
	}

	cout << DP[N][0] << '\n';
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Incorrect 0 ms 212 KB Output isn't correct
3 Halted 0 ms 0 KB -