# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
145136 |
2019-08-18T21:24:05 Z |
radugheo |
Mate (COCI18_mate) |
C++14 |
|
2000 ms |
60328 KB |
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
long long l, i, j, q, k, a, x, p;
long long r[2005][30], c[2005][2005];
long long d[2005][30][30], sol[2005][30][30];
char y, z, s[2005];
vector <long long> v[30];
int main(){
cin >> (s + 1);
l = strlen(s+1);
c[0][0] = 1;
for (i=1; i<=l; i++){
c[i][0] = 1;
for (j=1; j<=i; j++){
c[i][j] = (c[i-1][j-1] + c[i-1][j]);
if (c[i][j] >= MOD)
c[i][j] -= MOD;
}
}
for (i=1; i<=l; i++){
v[s[i] - 'a'].push_back(i);
}
for (i=l; i>=1; i--){
for (j=0; j<26; j++){
if (s[i] == j + 'a'){
r[i][j] = 1 + r[i+1][j];
}
else{
r[i][j] = r[i+1][j];
}
}
}
for (i=l; i>=1; i--){
for (j=0; j<26; j++){
for (q=0; q<26; q++){
if (s[i] == j + 'a'){
d[i][j][q] = r[i+1][q];
}
else{
d[i][j][q] = d[i+1][j][q];
}
}
}
}
for (i=2; i<=l; i++){
for (j=0; j<26; j++){
for (q=0; q<v[j].size(); q++){
p = v[j][q];
if (p >= i - 1){
for (k=0; k<26; k++){
sol[i][j][k] += ((d[p][j][k] * c[p-1][i-2])%MOD);
if (sol[i][j][k] >= MOD)
sol[i][j][k] -= MOD;
}
}
}
}
}
cin >> a;
for (i=1; i<=a; i++){
cin >> x >> y >> z;
cout << sol[x][y-'a'][z-'a'] << "\n";
}
return 0;
}
Compilation message
mate.cpp: In function 'int main()':
mate.cpp:53:24: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (q=0; q<v[j].size(); q++){
~^~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
1272 KB |
Output is correct |
2 |
Correct |
59 ms |
1272 KB |
Output is correct |
3 |
Correct |
67 ms |
1144 KB |
Output is correct |
4 |
Correct |
115 ms |
1288 KB |
Output is correct |
5 |
Correct |
428 ms |
5404 KB |
Output is correct |
6 |
Correct |
483 ms |
6092 KB |
Output is correct |
7 |
Correct |
359 ms |
5764 KB |
Output is correct |
8 |
Correct |
324 ms |
5596 KB |
Output is correct |
9 |
Execution timed out |
2048 ms |
60328 KB |
Time limit exceeded |
10 |
Execution timed out |
2057 ms |
60324 KB |
Time limit exceeded |