답안 #94685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
94685 2019-01-22T14:08:36 Z quoriess Mate (COCI18_mate) C++14
100 / 100
1870 ms 35576 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef pair<lli,lli> pii;
#define dbg(x) cout<<#x<<" has a value of: "<<x<<"\n";
#define usize(x) (int)(x.size())
#define plist(x) for(int i=0;i<usize(x);i++)cout<<"eleman "<<i<<" = "<<x[i]<<"\n";
#define foreach(x) for(auto item:x)
#define fill(s,x) for(int i=0;i<x;i++)cin>>s[i];
#define in(veriler,a) (veriler.find(a)!=veriler.end())
#define btw(x,y,z) x>=y && x<=z
std::ostream& operator<<(std::ostream& os, pair<int,int> p) {
    os << p.first << ", " << p.second;
    return os;
}
const lli MOD=1e9+7;
const int MAXN=2005;
lli rmod(lli x){
	return ((x%MOD)+MOD)%MOD;
}
lli comb[MAXN][MAXN];
void precalc(){
	comb[0][0]=1;
	comb[1][0]=comb[1][1]=1;
	for (int i = 2; i <MAXN ; i++)
	{
		comb[i][0]=1;
		for (int j = 1; j <= i; j++)
		{
			comb[i][j]=rmod(comb[i-1][j]+comb[i-1][j-1]);
		}
	}
}
int main(){
	precalc();
	string s;
	cin>>s;
	int n=s.size();
	vector<vector<int> > pre(n+1,vector<int>(26));
	for (int i = 1; i <= n; i++)
	{
		for(int j=0;j<26;j++){
			pre[i][j]=pre[i-1][j];
		}
		pre[i][s[i-1]-97]=pre[i-1][s[i-1]-97]+1;
	}
	vector<vector<vector<int> > > calcpre(26,vector<vector<int> >(n+1,vector<int>(26,0)));
	for (int i = 1; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			for (int k = 0; k < 26; k++)
			{
				calcpre[s[i-1]-97][j][k]+=rmod((pre[n][k]-pre[i][k])*comb[i-1][j]);
				calcpre[s[i-1]-97][j][k]%=MOD;
			}
		}
	}
	int q;
	cin>>q;
	for (int i = 0; i < q; i++)
	{
		int x;
		cin>>x;
		char c1,c2;
		cin>>c1>>c2;
		cout<<rmod(calcpre[c1-97][x-2][c2-97])<<"\n";
	}
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 69 ms 23416 KB Output is correct
2 Correct 52 ms 23288 KB Output is correct
3 Correct 58 ms 23288 KB Output is correct
4 Correct 83 ms 23416 KB Output is correct
5 Correct 255 ms 24700 KB Output is correct
6 Correct 286 ms 24988 KB Output is correct
7 Correct 224 ms 24696 KB Output is correct
8 Correct 205 ms 24568 KB Output is correct
9 Correct 1870 ms 35576 KB Output is correct
10 Correct 1827 ms 35576 KB Output is correct