Submission #1303026

#TimeUsernameProblemLanguageResultExecution timeMemory
1303026fuyu캥거루 (CEOI16_kangaroo)C++20
100 / 100
25 ms14148 KiB
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define pb push_back
#define ins insert
#define fi first
#define se second
#define MASK(x) (1ULL << (x))
#define BIT(x, k) ((x) >> (k) & 1)
#define ALL(x) (x).begin(), (x).end()
#define TIME (1.0 * clock() / CLOCKS_PER_SEC)

#define file "KANGAROO"

template<typename T1, typename T2> bool minimize(T1 &a, const T2 &b) {if (a > b) a = b; else return 0; return 1;}
template<typename T1, typename T2> bool maximize(T1 &a, const T2 &b) {if (a < b) a = b; else return 0; return 1;}

void fastio(){
	if (fopen(file".INP", "r")){
		freopen(file".INP", "r", stdin);
		freopen(file".OUT", "w", stdout);
	}
}

const int maxn = 2e3 + 5;
const int mod = 1e9 + 7;

void add(int &a, const int &b){
	a += b;
	if (a >= mod)
		a -= mod;
}

int mul(const int &a, const int &b){
	return (1ll * a * b) % mod;
}

int n, st, en;
int dp[maxn][maxn];

signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);

	fastio();

	cin >> n >> st >> en;

	dp[0][0] = 1;

	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= i; ++j){
			//i = st hoac i = en
			if (i == st || i == en){
				add(dp[i][j],
					dp[i - 1][j]);

				add(dp[i][j],
					dp[i - 1][j - 1]);
			}
			//i khac st va en
			else{
				//Noi 2 tplt
				if (j < i)
					add(dp[i][j],
						mul(dp[i - 1][j + 1], j));
				//Tao 1 tplt moi
				add(dp[i][j],
					mul(dp[i - 1][j - 1],
						j - (i > st) - (i > en)));
			}
		}

	cout << dp[n][1] << '\n';

	cerr << "\nTime ran : " << TIME << "s.\n";
	return 0;
}

Compilation message (stderr)

kangaroo.cpp: In function 'void fastio()':
kangaroo.cpp:22:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |                 freopen(file".INP", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:23:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |                 freopen(file".OUT", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...