# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
145132 |
2019-08-18T21:16:10 Z |
radugheo |
Mate (COCI18_mate) |
C++14 |
|
2000 ms |
35200 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][30];
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])%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;
}
}
}
}
}
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:51: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 |
Incorrect |
88 ms |
1144 KB |
Output isn't correct |
2 |
Incorrect |
57 ms |
1016 KB |
Output isn't correct |
3 |
Incorrect |
67 ms |
1016 KB |
Output isn't correct |
4 |
Incorrect |
115 ms |
1020 KB |
Output isn't correct |
5 |
Incorrect |
413 ms |
4216 KB |
Output isn't correct |
6 |
Incorrect |
468 ms |
4216 KB |
Output isn't correct |
7 |
Incorrect |
369 ms |
4088 KB |
Output isn't correct |
8 |
Incorrect |
324 ms |
3956 KB |
Output isn't correct |
9 |
Execution timed out |
2008 ms |
35200 KB |
Time limit exceeded |
10 |
Execution timed out |
2036 ms |
34952 KB |
Time limit exceeded |