답안 #707792

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
707792 2023-03-10T06:58:28 Z TAhmed33 Mate (COCI18_mate) C++
0 / 100
52 ms 66360 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
vector <int> arr;
int n;
int dp[26][26][2001] = {};
const int MOD = 1e9 + 7;
int ncr[2001][2001];
signed main () {
	for (int i = 0; i <= 2000; i++) {
		for (int j = 0; j <= 2000; 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];
				ncr[i][j] %= MOD;
			}
		}
	}
	string s;
	cin >> s;
	n = s.length();
	arr.push_back(8);
	for (int i = 0; i < n; i++) {
		arr.push_back(s[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];
				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 Runtime error 47 ms 66360 KB Execution killed with signal 11
2 Runtime error 45 ms 66200 KB Execution killed with signal 11
3 Runtime error 48 ms 66336 KB Execution killed with signal 11
4 Runtime error 45 ms 66096 KB Execution killed with signal 11
5 Runtime error 45 ms 66184 KB Execution killed with signal 11
6 Runtime error 52 ms 65956 KB Execution killed with signal 11
7 Runtime error 49 ms 65932 KB Execution killed with signal 11
8 Runtime error 52 ms 65912 KB Execution killed with signal 11
9 Runtime error 50 ms 65916 KB Execution killed with signal 11
10 Runtime error 51 ms 65864 KB Execution killed with signal 11