# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
999015 |
2024-06-15T05:02:42 Z |
vjudge1 |
Trener (COCI20_trener) |
C++17 |
|
747 ms |
16700 KB |
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 55, K = 1505;
const ll base = 727, mod = 1e9 + 7;
ll n, k;
map<string, ll> cnt[N], dp[N];
int main(){
cin >> n >> k;
for (ll i = 1; i <= n; i ++){
for (ll j = 1; j <= k; j ++){
string s;
cin >> s;
cnt[i][s]++;
dp[i][s]++;
}
}
// cout << endl;
// for (int i = 1; i <= n; i ++){
// cout << i << " : ";
// for (auto [H, val] : dp[i])
// cout << H << " -- " << val << ", ";
// cout << endl;
// }
// cout << endl;
for (ll i = n - 1; i > 0; i --){
for (auto [S, C] : cnt[i]){
ll sm = 0;
// cout << "HASH = " << H << endl;
string pref = S + '#';
string suff = '#' + S;
map<string, bool> seen;
for (int c = 'a'; c <= 'z'; c ++){
// cout << "can have edge with " << nh << endl;
pref[i] = suff[0] = c;
if (!seen[pref] and dp[i + 1].find(pref) != dp[i + 1].end())
sm = (sm + dp[i + 1][pref]) % mod;
seen[pref] = 1;
if (!seen[suff] and dp[i + 1].find(suff) != dp[i + 1].end())
sm = (sm + dp[i + 1][suff]) % mod;
seen[suff] = 1;
}
dp[i][S] = C * sm % mod;
}
}
// cout << endl;
// for (int i = 1; i <= n; i ++){
// cout << i << " : ";
// for (auto [H, val] : dp[i])
// cout << H << " -- " << val << ", ";
// cout << endl;
// }
// cout << endl;
ll ans = 0;
for (auto [S, val] : dp[1])
ans = (ans + val) % mod;
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
55 ms |
1536 KB |
Output is correct |
2 |
Correct |
50 ms |
1372 KB |
Output is correct |
3 |
Correct |
48 ms |
1368 KB |
Output is correct |
4 |
Correct |
3 ms |
348 KB |
Output is correct |
5 |
Correct |
34 ms |
1308 KB |
Output is correct |
6 |
Correct |
35 ms |
1116 KB |
Output is correct |
7 |
Correct |
3 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
344 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
55 ms |
1536 KB |
Output is correct |
6 |
Correct |
50 ms |
1372 KB |
Output is correct |
7 |
Correct |
48 ms |
1368 KB |
Output is correct |
8 |
Correct |
3 ms |
348 KB |
Output is correct |
9 |
Correct |
34 ms |
1308 KB |
Output is correct |
10 |
Correct |
35 ms |
1116 KB |
Output is correct |
11 |
Correct |
3 ms |
348 KB |
Output is correct |
12 |
Correct |
723 ms |
16484 KB |
Output is correct |
13 |
Correct |
736 ms |
16464 KB |
Output is correct |
14 |
Correct |
747 ms |
16700 KB |
Output is correct |
15 |
Correct |
725 ms |
16464 KB |
Output is correct |
16 |
Correct |
31 ms |
432 KB |
Output is correct |
17 |
Correct |
504 ms |
12544 KB |
Output is correct |
18 |
Correct |
488 ms |
12576 KB |
Output is correct |
19 |
Correct |
498 ms |
12500 KB |
Output is correct |
20 |
Correct |
518 ms |
12368 KB |
Output is correct |
21 |
Correct |
487 ms |
12376 KB |
Output is correct |
22 |
Correct |
34 ms |
348 KB |
Output is correct |