#include <bits/stdc++.h>
using namespace std;
const int mod =1e9+7;
int dp[2003][28][28];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie (NULL);
string s;cin>>s;
int n=s.size();
for(int i=0;i<n;i++)
{
for(int j=i+1;j>2;j--)
{
for(int u=1;u<=26;u++)
{
for(int h=1;h<27;h++)
{
dp[j][u][s[i]-'0'-48]+=dp[j-1][h][u]%mod;
dp[j][u][s[i]-'0'-48]%=mod;
}
}
}
for(int j=1;j<=26;j++)
{
dp[2][j][s[i]-'0'-48]+=dp[1][0][j];
dp[2][j][s[i]-'0'-48]%=mod;
}
dp[1][0][s[i]-'0'-48]++;
}
char c,c1;
int x;
int q;cin>>q;
while (q--)
{
cin>>x;
cin>>c>>c1;
cout<<dp[x][c-'0'-48][c1-'0'-48]%mod<<endl;
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
44 ms |
760 KB |
Output is correct |
2 |
Correct |
31 ms |
632 KB |
Output is correct |
3 |
Correct |
48 ms |
632 KB |
Output is correct |
4 |
Correct |
65 ms |
760 KB |
Output is correct |
5 |
Correct |
267 ms |
2808 KB |
Output is correct |
6 |
Correct |
299 ms |
2936 KB |
Output is correct |
7 |
Correct |
248 ms |
2552 KB |
Output is correct |
8 |
Correct |
247 ms |
2372 KB |
Output is correct |
9 |
Execution timed out |
2065 ms |
3304 KB |
Time limit exceeded |
10 |
Execution timed out |
2064 ms |
3332 KB |
Time limit exceeded |