제출 #1282348

#제출 시각아이디문제언어결과실행 시간메모리
1282348kawhietMate (COCI18_mate)C++20
0 / 100
2096 ms20248 KiB
#include <bits/stdc++.h> using namespace std; constexpr int mod = 1e9 + 7; constexpr int N = 2001; int C[N][N]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); for (int i = 0; i < N; i++) { for (int j = 0; j < N; j++) { if (j == 0 || j == i) { C[i][j] = 1; } else { C[i][j] = (C[i - 1][j] + C[i - 1][j - 1]) % mod; } } } string a; cin >> a; int n = a.size(); int q; cin >> q; while (q--) { int d; string s; cin >> d >> s; vector<int> suf(n + 2); for (int i = n - 1; i >= 0; i--) { suf[i] = suf[i + 1] + (a[i] == s[1]); } int res = 0; for (int i = 0; i < n; i++) { if (a[i] == s[0]) { res += 1LL * C[i][d - 2] * suf[i + 1] % mod; res %= mod; } } cout << res << '\n'; } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...