# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
297512 |
2020-09-11T15:38:13 Z |
Hehehe |
Mate (COCI18_mate) |
C++14 |
|
578 ms |
56312 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 = 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 |
7 ms |
1280 KB |
Output is correct |
2 |
Incorrect |
6 ms |
1280 KB |
Output isn't correct |
3 |
Correct |
5 ms |
1152 KB |
Output is correct |
4 |
Incorrect |
8 ms |
1536 KB |
Output isn't correct |
5 |
Incorrect |
34 ms |
5368 KB |
Output isn't correct |
6 |
Incorrect |
40 ms |
5624 KB |
Output isn't correct |
7 |
Incorrect |
30 ms |
5120 KB |
Output isn't correct |
8 |
Incorrect |
29 ms |
4992 KB |
Output isn't correct |
9 |
Incorrect |
566 ms |
55928 KB |
Output isn't correct |
10 |
Incorrect |
578 ms |
56312 KB |
Output isn't correct |