# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
239025 |
2020-06-14T07:11:56 Z |
VEGAnn |
Mate (COCI18_mate) |
C++14 |
|
2000 ms |
39388 KB |
#include <bits/stdc++.h>
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")
#define i2 array<int,2>
#define PB push_back
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
using namespace std;
typedef long long ll;
const int N = 2010;
const ll OO = 1e18;
const int md = int(1e9) + 7;
unordered_map<string, int> mem[N];
string s, st;
int n, C[N][N];
ll cnt[N][26], ans;
int sum(int x, int y){
x += y;
if (x >= md)
x -= md;
return x;
}
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef _LOCAL
freopen("in.txt","r",stdin);
#endif // _LOCAL
cin >> s;
n = sz(s);
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++)
cnt[i][s[j] - 'a']++;
C[0][0] = 1;
for (int i = 1; i <= n; i++){
C[i][0] = C[i][i] = 1;
for (int j = 1; j < n; j++)
C[i][j] = sum(C[i - 1][j], C[i - 1][j - 1]);
}
int qq; cin >> qq;
for (; qq; qq--){
int d; cin >> d >> st;
if (mem[d].find(st) != mem[d].end()){
cout << mem[d][st] << '\n';
continue;
}
d -= 2;
int ch = (st[1] - 'a');
ans = 0;
for (int i = 0; i < n; i++)
if (s[i] == st[0]) {
if (cnt[i][ch] == 0) break;
(ans += cnt[i][ch] * C[i][d]) %= md;
}
mem[d + 2][st] = ans;
cout << ans << '\n';
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2048 KB |
Output is correct |
2 |
Correct |
13 ms |
1664 KB |
Output is correct |
3 |
Correct |
14 ms |
1792 KB |
Output is correct |
4 |
Correct |
21 ms |
2304 KB |
Output is correct |
5 |
Correct |
97 ms |
8568 KB |
Output is correct |
6 |
Correct |
103 ms |
8824 KB |
Output is correct |
7 |
Correct |
83 ms |
7928 KB |
Output is correct |
8 |
Correct |
74 ms |
7420 KB |
Output is correct |
9 |
Execution timed out |
2086 ms |
39388 KB |
Time limit exceeded |
10 |
Execution timed out |
2088 ms |
39248 KB |
Time limit exceeded |