Submission #96767

# Submission time Handle Problem Language Result Execution time Memory
96767 2019-02-11T19:39:01 Z Rouge_Hugo Mate (COCI18_mate) C++14
100 / 100
1557 ms 22008 KB
#include <bits/stdc++.h>
using namespace std;
const int mod =1e9+7;
long long  dp[2003][28][28],r[2003][27];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie (NULL);
	string s;cin>>s;
	int n=s.size();
		long long sum=0;
	for(int i=0;i<n;i++)
	{
		for(int j=n;j>1;j--)
		{
			sum=0;
			for(int u=1;u<27;u++)
			{
				dp[j][u][s[i]-'0'-48]+=r[j-1][u]%mod;
				sum+=r[j-1][u]%mod;
			}
			r[j][s[i]-'0'-48]+=sum%mod;
			r[j][s[i]-'0'-48]%=mod;
		}
	r[1][s[i]-'0'-48]+=1;
	}
	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;

}
# Verdict Execution time Memory Grader output
1 Correct 44 ms 888 KB Output is correct
2 Correct 29 ms 760 KB Output is correct
3 Correct 31 ms 760 KB Output is correct
4 Correct 51 ms 888 KB Output is correct
5 Correct 184 ms 3320 KB Output is correct
6 Correct 219 ms 3524 KB Output is correct
7 Correct 168 ms 3192 KB Output is correct
8 Correct 150 ms 2936 KB Output is correct
9 Correct 1557 ms 21908 KB Output is correct
10 Correct 1517 ms 22008 KB Output is correct