답안 #707795

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707795 2023-03-10T07:06:29 Z TAhmed33 Mate (COCI18_mate) C++
80 / 100
2000 ms 17104 KB
#include <bits/stdc++.h>
using namespace std;
vector <int> arr;
int n;
int dp[2001][26][26] = {};
const int MOD = 1e9 + 7;
int ncr[2001][2001];
int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	n = s.length();
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			if (j == 0 || j == i) {
				ncr[i][j] = 1;
			} else if (i < j) {
				ncr[i][j] = 0;
			} else {
				ncr[i][j] = ncr[i - 1][j] + ncr[i - 1][j - 1];
				if (ncr[i][j] >= MOD) ncr[i][j] -= MOD;
			}
		}
	}
	arr.push_back(8);
	for (auto i : s) arr.push_back(i - 'a');
	for (int i = 1; i <= n - 1; i++) {
		for (int j = i + 1; j <= n; j++) {
			for (int k = 2; k <= i + 1; k++) {
				dp[k][arr[i]][arr[j]] += ncr[i - 1][i + 1 - k];
				if (dp[k][arr[i]][arr[j]] >= MOD) dp[k][arr[i]][arr[j]] -= MOD;
			}
		}
	}
	int q;
	cin >> q;
	while (q--) {
		int d;
		char a, b;
		cin >> d >> a >> b;
		int x = a - 'a';
		int y = b - 'a';
		cout << dp[d][x][y] << '\n';
	}
}
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 852 KB Output is correct
2 Correct 4 ms 728 KB Output is correct
3 Correct 4 ms 724 KB Output is correct
4 Correct 6 ms 836 KB Output is correct
5 Correct 35 ms 3532 KB Output is correct
6 Correct 37 ms 3660 KB Output is correct
7 Correct 32 ms 3316 KB Output is correct
8 Correct 30 ms 3040 KB Output is correct
9 Execution timed out 2100 ms 17104 KB Time limit exceeded
10 Execution timed out 2094 ms 17100 KB Time limit exceeded