Submission #405930

# Submission time Handle Problem Language Result Execution time Memory
405930 2021-05-17T05:08:32 Z AriaH Kangaroo (CEOI16_kangaroo) C++11
0 / 100
1 ms 332 KB
/** I can do this all day **/

#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;

typedef long long                   ll;
typedef long double                 ld;
typedef pair<int,int>               pii;
typedef pair<ll,ll>                 pll;
#define all(x)                      (x).begin(),(x).end()
#define F                           first
#define S                           second
#define Mp                          make_pair
#define SZ(x)			    		(int)x.size()
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);

const int N = 2e2 + 10;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const ll inf = 8e18;
const int LOG = 22;

ll pw(ll a , ll b, ll M)  { return (!b ? 1 : (b & 1 ? (a * pw(a * a % M, b / 2, M)) % M : pw(a * a % M, b / 2, M))); }

ll F[N], I[N];

ll E(ll r, ll n)
{
	if(r > n || r < 0) return 0;
	return F[n] * I[r] % mod * I[n - r] % mod;
}

int n, s, f;

ll dp[N][N][N];

int main()
{
	F[0] = 1;
	for(int i = 1; i < N; i ++) F[i] = F[i - 1] * i % mod;
	I[N - 1] = pw(F[N - 1], mod - 2, mod);
	for(int i = N - 2; ~i; i --)
	{
		I[i] = I[i + 1] * (i + 1) % mod;
	}
	scanf("%d%d%d", &n, &s, &f);
	dp[0][0][0] = 1;
	for(int i = 0; i < n; i ++)
	{
		for(int a = 0; a <= i; a ++)
		{
			for(int b = 0; b <= i - a; b ++)
			{
				ll cu = dp[i][a][b];
				if(i + 1 == s || i + 1 == f)
				{
					if(a) dp[i + 1][a - 1][b + 1] = (dp[i + 1][a - 1][b + 1] + cu * a) % mod;
					if(b) dp[i + 1][a][b - 1] = (dp[i + 1][a][b - 1] + cu * b) % mod;
					dp[i + 1][a][b + 1] = (dp[i + 1][a][b + 1] + cu) % mod;
				}
				else
				{
					/// 2 ta a yal bede
					if(a > 1) dp[i + 1][a - 2][b + 2] = (dp[i + 1][a - 2][b + 2] + E(2, a) * cu) % mod;
					/// 2 ta b yal bede
					if(b > 1) dp[i + 1][a][b - 2] = (dp[i + 1][a][b - 2] + E(2, b) * cu) % mod;
					/// ye a, ye b
					if(a && b)
					{
						dp[i + 1][a - 1][b] = (dp[i + 1][a - 1][b] + cu * a * b) % mod;
					}
					/// ye a
					if(a)
					{
						dp[i + 1][a - 1][b + 2] = (dp[i + 1][a - 1][b + 2] + cu * a) % mod;
					}
					/// ye b
					if(b)
					{
						dp[i + 1][a][b] = (dp[i + 1][a][b] + cu * b) % mod;
					}
					/// hichi
					dp[i + 1][a + 1][b] = (dp[i + 1][a + 1][b] + cu) % mod;
				}
			}
		}
	}
	printf("%lld", dp[n][0][0]);
    return 0;
}

/** test corner cases(n = 1?) watch for overflow or minus indices **/

Compilation message

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   48 |  scanf("%d%d%d", &n, &s, &f);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 276 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 276 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 276 KB Output isn't correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 1 ms 276 KB Output isn't correct