# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
845332 |
2023-09-06T13:12:27 Z |
vjudge1 |
Trener (COCI20_trener) |
C++17 |
|
6 ms |
1628 KB |
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define int long long
const int mod = 1e9 + 7;
const int p = 31;
int HASH(string str){
int k = 1 , ret = 0;
for(auto itr : str){
ret = (ret + k * (itr - 'a')) % mod;
k = (k * p) % mod;
}
return ret;
}
void solve(){
int n,k;cin >> n >> k;
string v[n+1][k];
map < int , vector < int > > mpa;
for(int i = 1;i<=n;i++){
for(int j = 0;j<k;j++){
cin >> v[i][j];
mpa[HASH(v[i][j])].push_back(j);
}
}
int dp[n+1][k];
memset(dp , 0 , sizeof(dp));
for(int i = 0;i<k;i++)dp[1][i] = 1;
for(int i = 2;i<=n;i++){
for(int j = 0;j<k;j++){
vector < int > ind1 = mpa[HASH(string(v[i][j].begin() , v[i][j].end()-1))];
vector < int > ind2 = mpa[HASH(string(v[i][j].begin()+1 , v[i][j].end()))];
for(auto itr : ind2)ind1.push_back(itr);
sort(ind1.begin(),ind1.end());
ind1.resize(unique(ind1.begin() , ind1.end()) - ind1.begin());
for(auto itr : ind1){
dp[i][j] = (dp[i][j] + dp[i-1][itr]) % mod;
}
}
}
int ans = 0;
for(int i = 0;i<k;i++)ans = (ans + dp[n][i]) % mod;
cout << ans << endl;
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);
int testcase = 1;//cin >> testcase;
while(testcase--)solve();
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
6 ms |
1628 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |