# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
239018 | VEGAnn | Mate (COCI18_mate) | C++14 | 2093 ms | 19332 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define i2 array<int,2>
#define PB push_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 2010;
const ll OO = 1e18;
const int md = int(1e9) + 7;
string s, st;
int n, cnt[N][26], C[N][N], ans;
int sum(int x, int y){
x += y;
if (x >= md)
x -= md;
return x;
}
int mult(int x, int y) { return (1ll * x * y) % md; }
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> s;
n = sz(s);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
cnt[i][s[j] - 'a']++;
C[0][0] = 1;
for (int i = 1; i <= n; i++){
C[i][0] = C[i][i] = 1;
for (int j = 1; j < n; j++)
C[i][j] = sum(C[i - 1][j], C[i - 1][j - 1]);
}
int qq; cin >> qq;
for (; qq; qq--){
int d; cin >> d >> st;
d -= 2;
int ch = (st[1] - 'a');
ans = 0;
for (int i = 0; i < n; i++)
if (s[i] == st[0])
ans = sum(ans, mult(cnt[i][ch], C[i][d]));
cout << ans << '\n';
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |