# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
142513 | KCSC | Mate (COCI18_mate) | C++14 | 387 ms | 15180 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// Credits to Mihaela Cismaru pentru ca m-a ajutat sa corectez penalitatea asta
#include <bits/stdc++.h>
using namespace std;
const int DIM = 2005;
const int SIGMA = 26;
const int MOD = 1000000007;
char str[DIM], aux[3];
int dp[DIM][SIGMA][SIGMA], cnt[DIM][SIGMA], cmb[DIM][SIGMA];
int main(void) {
// freopen("mate.in", "r", stdin);
// freopen("mate.out", "w", stdout);
scanf("%s", str + 1);
int n = strlen(str + 1);
for (int i = 0; i <= n; ++i) {
cmb[i][0] = 1;
for (int j = 1; j <= i; ++j)
cmb[i][j] = (cmb[i - 1][j - 1] + cmb[i - 1][j]) % MOD;
}
for (int i = 1; i <= n; ++i)
for (int j = i + 1; j <= n; ++j)
++cnt[i][str[j] - 'a'];
for (int i = 1; i <= n; ++i)
for (int j = 0; j < i; ++j)
for (int k = 0; k < 26; ++k)
dp[j + 2][str[i] - 'a'][k] = (1LL * cmb[i - 1][j] * cnt[i][k] + dp[j + 2][str[i] - 'a'][k]) % MOD;
int q;
scanf("%d", &q);
while (q--) {
int x;
scanf("%d %s", &x, aux + 1);
printf("%d\n", dp[x][aux[1] - 'a'][aux[2] - 'a']);
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |