Submission #464822

#TimeUsernameProblemLanguageResultExecution timeMemory
464822TheScrasseTrener (COCI20_trener)C++17
110 / 110
832 ms43972 KiB
#include <bits/stdc++.h> using namespace std; #define nl "\n" #define nf endl #define ll long long #define pb push_back #define _ << ' ' << #define INF (ll)1e18 #define mod 1000000007 #define hmod 10000000000037 #define maxn 60 #define maxm 1510 ll i, i1, j, k, k1, t, n, m, res, flag[10], a, b; ll hx, hp[maxn], hc[maxn], hs[maxn][maxm][maxn]; ll dp[maxn][maxm]; string mt[maxn][maxm]; int main() { mt19937 rng(19938); ios::sync_with_stdio(0); cin.tie(0); #if !ONLINE_JUDGE && !EVAL ifstream cin("input.txt"); ofstream cout("output.txt"); #endif for (i = 0; i <= 25; i++) { hc[i] = uniform_int_distribution<ll>(1000 * i, 1000 * i + 999)(rng); } hx = uniform_int_distribution<ll>(30001, 40000)(rng); hp[0] = 1; for (i = 1; i < maxn; i++) hp[i] = (hx * hp[i - 1]) % hmod; cin >> n >> m; for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cin >> mt[i][j]; } } for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { for (k = 1; k <= i; k++) { hs[i][j][k] = (hs[i][j][k - 1] + hp[k - 1] * hc[(ll)mt[i][j][k - 1] - 'a']) % hmod; } } } for (j = 1; j <= m; j++) dp[1][j] = 1; for (i = 2; i <= n; i++) { for (j = 1; j <= m; j++) { for (k = 1; k <= m; k++) { if (hs[i][j][i - 1] == hs[i - 1][k][i - 1] || (hs[i][j][i] - hs[i][j][1] - hx * hs[i - 1][k][i - 1]) % hmod == 0) { dp[i][j] = (dp[i][j] + dp[i - 1][k]) % mod; } } if (i == n) res = (res + dp[i][j]) % mod; } } /* for (i = 1; i <= n; i++) { for (j = 1; j <= m; j++) { cout << dp[i][j] << ' '; } cout << nl; } */ cout << res << nl; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...