# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
297533 |
2020-09-11T15:46:43 Z |
Hehehe |
Mate (COCI18_mate) |
C++14 |
|
358 ms |
34552 KB |
#include<bits/stdc++.h> //:3
using namespace std;
typedef long long ll;
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define sz(x) (int)((x).size())
//#define int long long
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const ll inf = 2e9;
const ll mod = 1e9 + 7;
const int N = 2e3 + 11;
const int X = 1e6;
const ll INF64 = 3e18 + 1;
const double eps = 1e-14;
const double PI = acos(-1);
//ifstream in(".in");
//ofstream out(".out");
int n, m, a[N], c[N][N], dp[N][30][30], M[N][N];
string s;
void solve(){
cin >> s;
n = sz(s);
s = '.' + s;
for(int i = 1; i <= n; i++){
a[i] = s[i] - 'a' + 1;
}
c[0][0] = 1;
for(int i = 1; i <= n; i++){
c[i][0] = 1;
for(int j = 1; j <= i; j++){
c[i][j] = c[i - 1][j] + c[i - 1][j - 1];
if(c[i][j] >= mod)c[i][j] -= mod;
//cout << c[i][j] << ' ';
}//cout << '\n';
}
for(int i = 1; i <= n; i++){
for(int j = i + 1; j <= n; j++){
M[i][a[j]]++;
}
}
for(int len = 2; len <= n; len++){
for(int i = len - 1; i <= n; i++){
int x = a[i];
for(int y = 1; y <= 26; y++){
dp[len][x][y] += M[i][y]*c[i - 1][len - 2];
if(dp[len][x][y] >= mod)dp[len][x][y] -= mod;
}
}
}
int q;
cin >> q;
while(q--){
int x; char l, r;
cin >> x >> l >> r;
cout << dp[x][l - 'a' + 1][r - 'a' + 1] << '\n';
}
}
int32_t main(){
ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
//cout << setprecision(6) << fixed;
int T = 1;
//cin >> T;
while(T--){
solve();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
6 ms |
1024 KB |
Output is correct |
2 |
Incorrect |
4 ms |
896 KB |
Output isn't correct |
3 |
Correct |
5 ms |
896 KB |
Output is correct |
4 |
Incorrect |
8 ms |
1024 KB |
Output isn't correct |
5 |
Incorrect |
31 ms |
3748 KB |
Output isn't correct |
6 |
Incorrect |
36 ms |
3772 KB |
Output isn't correct |
7 |
Incorrect |
27 ms |
3576 KB |
Output isn't correct |
8 |
Incorrect |
24 ms |
3456 KB |
Output isn't correct |
9 |
Incorrect |
358 ms |
34552 KB |
Output isn't correct |
10 |
Incorrect |
354 ms |
34552 KB |
Output isn't correct |