# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
846017 |
2023-09-07T06:09:48 Z |
vjudge1 |
Trener (COCI20_trener) |
C++17 |
|
169 ms |
13088 KB |
/**
* author: kututay
* created: 06.09.2023 16:41:38
**/
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#include "/Users/kutay/CP/templates/debug.h"
#else
#define debug(...) void(38)
#endif
#define int long long
const int mod = 1e9 + 7;
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, k; cin >> n >> k;
vector<vector<int>> a(n * k + 2);
vector<int> dp(n * k + 2, -1), cnt(n * k + 2);
function<int(int)> f = [&](int node) {
if (dp[node] != -1) return dp[node];
int res = 0;
sort(a[node].begin(), a[node].end());
for (int i = 0; i < (int) a[node].size(); i++) {
int next = a[node][i];
if (i > 0 && a[node][i - 1] == next) continue;
res += (cnt[node] * f(next)) % mod;
res %= mod;
}
return dp[node] = res;
};
map<string, int> m;
int count = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < k; j++) {
string s; cin >> s;
if (m.count(s) == 0) {
m[s] = ++count;
}
int node = m[s];
cnt[node]++;
if (i == n - 1) dp[node] = cnt[node];
if (i > 0) {
if (m.count(s.substr(0, i))) a[m[s.substr(0, i)]].emplace_back(node);
if (m.count(s.substr(1, i))) a[m[s.substr(1, i)]].emplace_back(node);
} else {
if (cnt[node] == 1) {
a[n * k + 1].emplace_back(node);
}
}
}
}
cnt[n * k + 1] = 1;
cout << f(n * k + 1) << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
8 ms |
1116 KB |
Output is correct |
2 |
Correct |
7 ms |
1168 KB |
Output is correct |
3 |
Correct |
7 ms |
1160 KB |
Output is correct |
4 |
Correct |
2 ms |
604 KB |
Output is correct |
5 |
Correct |
7 ms |
1032 KB |
Output is correct |
6 |
Correct |
8 ms |
1116 KB |
Output is correct |
7 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
8 ms |
1116 KB |
Output is correct |
6 |
Correct |
7 ms |
1168 KB |
Output is correct |
7 |
Correct |
7 ms |
1160 KB |
Output is correct |
8 |
Correct |
2 ms |
604 KB |
Output is correct |
9 |
Correct |
7 ms |
1032 KB |
Output is correct |
10 |
Correct |
8 ms |
1116 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
147 ms |
13088 KB |
Output is correct |
13 |
Correct |
145 ms |
12880 KB |
Output is correct |
14 |
Correct |
169 ms |
13016 KB |
Output is correct |
15 |
Correct |
155 ms |
12884 KB |
Output is correct |
16 |
Correct |
29 ms |
4700 KB |
Output is correct |
17 |
Correct |
132 ms |
10832 KB |
Output is correct |
18 |
Correct |
136 ms |
11056 KB |
Output is correct |
19 |
Correct |
143 ms |
10820 KB |
Output is correct |
20 |
Correct |
135 ms |
10864 KB |
Output is correct |
21 |
Correct |
127 ms |
11004 KB |
Output is correct |
22 |
Correct |
42 ms |
4772 KB |
Output is correct |