# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
391678 | phathnv | Trener (COCI20_trener) | C++11 | 61 ms | 8216 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define mp make_pair
#define X first
#define Y second
#define taskname "TRENER"
using namespace std;
typedef long long ll;
typedef pair <int, int> ii;
const int N = 51;
const int K = 1501;
const int base = 163;
const int MOD = 1e9 + 7;
int n, k;
char a[N][K][N];
ll hashed[N][K][3], pw[N];
int dp[N][K];
void readInput(){
scanf("%d %d", &n, &k);
for(int i = 1; i <= n; i++)
for(int j = 1; j <= k; j++)
scanf("%s", a[i][j] + 1);
}
void prepare(){
pw[0] = 1;
for(int i = 1; i <= n; i++)
pw[i] = pw[i - 1] * base;
for(int i = 1; i <= n; i++)
for(int j = 1; j <= k; j++){
ll val = 0;
for(int p = 1; p < i; p++)
val = val * base + a[i][j][p];
hashed[i][j][0] = val;
val = val * base + a[i][j][i];
hashed[i][j][1] = val - a[i][j][1] * pw[i - 1];
hashed[i][j][2] = val;
}
}
void add(int &x, const int &y){
x += y;
x -= (x >= MOD) * MOD;
}
void solve(){
for(int i = 1; i <= k; i++)
dp[1][i] = 1;
for(int i = 2; i <= n; i++){
map <ll, int> d;
for(int j = 1; j <= k; j++)
add(d[hashed[i - 1][j][2]], dp[i - 1][j]);
for(int j = 1; j <= k; j++){
add(dp[i][j], d[hashed[i][j][0]]);
if (hashed[i][j][0] != hashed[i][j][1])
add(dp[i][j], d[hashed[i][j][1]]);
}
}
int res = 0;
for(int i = 1; i <= k; i++)
add(res, dp[n][i]);
printf("%d", res);
}
int main(){
readInput();
prepare();
solve();
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |