Submission #297533

#TimeUsernameProblemLanguageResultExecution timeMemory
297533HeheheMate (COCI18_mate)C++14
20 / 100
358 ms34552 KiB
#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 timeMemoryGrader output
Fetching results...