Submission #1095698

#TimeUsernameProblemLanguageResultExecution timeMemory
1095698vjudge1Kangaroo (CEOI16_kangaroo)C++17
100 / 100
32 ms31864 KiB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

ll N, cs, cf;
ll DP[2007][2007];
const ll mod = 1e9 + 7;

void Cong(ll& a, ll b) {
	a = (a + b) % mod;
}

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

int main() {
	ios_base :: sync_with_stdio(0);
	cin.tie(0); cout.tie(0); cerr.tie(0);
	if (fopen("FILE.INP", "r")) {
		freopen("FILE.INP", "r", stdin);
		freopen("FILE.OUT", "w", stdout);
	}

	cin >> N >> cs >> cf;
	DP[1][1] = 1;
	for(int i = 2; i <= N; ++i) {
		for(int j = 1; j <= N; ++j) {
			if (i == cs || i == cf) {
				DP[i][j] = DP[i - 1][j - 1]; // i là tp riêng biệt
				Cong(DP[i][j], DP[i - 1][j]); // thêm i vào 1 tp có sẵn rồi cho về cuối 
				//cerr << i << " " << j << " " << DP[i][j] << '\n';
				continue;
			}

			DP[i][j] = Tich(DP[i - 1][j + 1], j); // nối tp1-i-tp2
			Cong(DP[i][j], Tich(DP[i -1][j - 1], (j - (cs < i) - (cf < i)))); 
			// i là tp riêng biệt : xét cả các TH đã có biên
			// Ko thêm i vào tp kiểu (tp-i) hay (i-tp) vì tính chất đặc biệt của bài này
			//cerr << i << " " << j << " " << DP[i][j] << '\n';
		}
	}

	cout << DP[N][1] << '\n';
}

Compilation message (stderr)

kangaroo.cpp: In function 'int main()':
kangaroo.cpp:21:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |   freopen("FILE.INP", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kangaroo.cpp:22:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   22 |   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...