# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
85840 |
2018-11-21T22:09:32 Z |
kraljlavova1 |
Mate (COCI18_mate) |
C++11 |
|
2000 ms |
102828 KB |
#include<bits/stdc++.h>
using namespace std;
typedef long long int llint;
const int MOD=1e9+7,MAXQ=500010,MAXS=2010;
string s,xy[MAXQ];
llint sol[MAXS][26][26];
int q,len,l[MAXQ];
map<string,vector<int> >mp;
map<pair<string,int>,int>bio;
llint povrh[MAXS][MAXS];
void pov(){
povrh[0][0]=1;
for(int i=1;i<MAXS;i++){
for(int j=0;j<MAXS;j++){
if(j==0){
povrh[i][j]=1;
continue;
}
povrh[i][j]=povrh[i-1][j]+povrh[i-1][j-1];
povrh[i][j]%=MOD;
}
}
}
int main(){
pov();
cin>>s;
cin>>q;
len=s.length();
for(int i=0;i<q;i++){
cin>>l[i]>>xy[i];
if(!bio[{xy[i],l[i]}]){
mp[xy[i]].push_back(l[i]);
bio[{xy[i],l[i]}]=1;
}
}
for(int i=0;i<len;i++){
for(int j=i+1;j<len;j++){
string a="";
a+=s[i];
a+=s[j];
for(int k=0;k<mp[a].size();k++){
int d=mp[a][k];
sol[d][a[0]-'a'][a[1]-'a']+=povrh[i][d-2];
sol[d][a[0]-'a'][a[1]-'a']%=MOD;
}
}
}
for(int i=0;i<q;i++){
cout<<sol[l[i]][xy[i][0]-'a'][xy[i][1]-'a']<<"\n";
}
return 0;
}
Compilation message
mate.cpp: In function 'int main()':
mate.cpp:41:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k=0;k<mp[a].size();k++){
~^~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
97 ms |
49884 KB |
Output is correct |
2 |
Correct |
77 ms |
49884 KB |
Output is correct |
3 |
Correct |
104 ms |
49884 KB |
Output is correct |
4 |
Correct |
106 ms |
50372 KB |
Output is correct |
5 |
Correct |
617 ms |
58264 KB |
Output is correct |
6 |
Correct |
633 ms |
58880 KB |
Output is correct |
7 |
Correct |
539 ms |
58880 KB |
Output is correct |
8 |
Correct |
498 ms |
58880 KB |
Output is correct |
9 |
Execution timed out |
2080 ms |
102828 KB |
Time limit exceeded |
10 |
Execution timed out |
2087 ms |
102828 KB |
Time limit exceeded |