Submission #241882

# Submission time Handle Problem Language Result Execution time Memory
241882 2020-06-26T08:33:57 Z SorahISA Trener (COCI20_trener) C++17
110 / 110
266 ms 10488 KB
#include <bits/stdc++.h>
using namespace std;

#define int long long

#define fastIO() ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

const int mod = 1E9 + 7;

int _hash(string s) {
    int p = 257, mod = 13302843816923LL;
    int ans = 0;
    for (auto c : s) ans = (ans * p + c) % mod;
    return ans;
}

int32_t main() {
    int n, k;
    cin >> n >> k;
    
    string all[n][k];
    int hashes[n][k][3]; /// prefix, suffix, all
    
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < k; ++j) {
            cin >> all[i][j];
            hashes[i][j][2] = _hash(all[i][j]);
            if (!i) continue;
            hashes[i][j][0] = _hash(all[i][j].substr(0, i));
            hashes[i][j][1] = _hash(all[i][j].substr(1));
        }
    }
    
    int dp[n][k];
    for (int i = 0; i < n; ++i) memset(dp[i], 0x00, sizeof(dp[i]));
    
    for (int j = 0; j < k; ++j) dp[0][j] = 1;
    
    for (int i = 1; i < n; ++i) {
        for (int j2 = 0; j2 < k; ++j2) {
            for (int j1 = 0; j1 < k; ++j1) {
                if (hashes[i][j2][0] == hashes[i-1][j1][2] or hashes[i][j2][1] == hashes[i-1][j1][2]) {
                    dp[i][j2] += dp[i-1][j1];
                }
            }
            dp[i][j2] %= mod;
        }
    }
    
    int ans = 0;
    for (int j = 0; j < k; ++j) ans += dp[n-1][j];
    
    cout << ans%mod << "\n";
    
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 1024 KB Output is correct
2 Correct 15 ms 1024 KB Output is correct
3 Correct 15 ms 1024 KB Output is correct
4 Correct 15 ms 1024 KB Output is correct
5 Correct 15 ms 1024 KB Output is correct
6 Correct 15 ms 1024 KB Output is correct
7 Correct 15 ms 1024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 256 KB Output is correct
2 Correct 5 ms 256 KB Output is correct
3 Correct 4 ms 256 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 15 ms 1024 KB Output is correct
6 Correct 15 ms 1024 KB Output is correct
7 Correct 15 ms 1024 KB Output is correct
8 Correct 15 ms 1024 KB Output is correct
9 Correct 15 ms 1024 KB Output is correct
10 Correct 15 ms 1024 KB Output is correct
11 Correct 15 ms 1024 KB Output is correct
12 Correct 243 ms 10488 KB Output is correct
13 Correct 241 ms 10360 KB Output is correct
14 Correct 255 ms 10488 KB Output is correct
15 Correct 248 ms 10488 KB Output is correct
16 Correct 248 ms 10360 KB Output is correct
17 Correct 266 ms 10484 KB Output is correct
18 Correct 262 ms 10360 KB Output is correct
19 Correct 264 ms 10360 KB Output is correct
20 Correct 259 ms 10360 KB Output is correct
21 Correct 259 ms 10360 KB Output is correct
22 Correct 248 ms 10488 KB Output is correct