Submission #998997

#TimeUsernameProblemLanguageResultExecution timeMemory
998997vjudge1Trener (COCI20_trener)C++17
110 / 110
772 ms8688 KiB
#include<bits/stdc++.h> using namespace std; const int mod = 1e9+7, base = 727; int main() { int n, k; cin >> n >> k; string s[n][k]; int hsh[n][k]; for(int i = 0; i < n; i ++) for(int j = 0; j < k; j++) cin >> s[i][j]; int dp[n][k]; for(int i = 0; i < k; i++) dp[0][i] = 1; for(int i = 0; i < k ; i++) hsh[0][i] = s[0][i][0] % mod; for(int i = 1; i < n; i ++) { for(int j = 0; j < k; j++) { dp[i][j] = 0; int hshp = 0, hshs = 0, hshc = 0; for(int l = 0; l < s[i][j].size(); l++) hshc = (1ll * hshc * base % mod + s[i][j][l]) % mod; for(int l = 0; l + 1 < s[i][j].size(); l++) hshp = (1ll * hshp * base % mod + s[i][j][l]) % mod; for(int l = 1; l < s[i][j].size(); l++) hshs = (1ll * hshs * base % mod + s[i][j][l]) % mod; hsh[i][j] = hshc; for(int l = 0; l < k; l++) if(hsh[i - 1][l] == hshp || hsh[i - 1][l] == hshs) dp[i][j] = (dp[i][j] + dp[i - 1][l]) % mod; // cerr << "dp[" << i << "][" << j << "] = " << dp[i][j] << endl; } } int ans = 0; for(int i = 0; i < k; i ++) ans = (ans + dp[n - 1][i]) % mod; cout << ans << endl; return 0; }

Compilation message (stderr)

trener.cpp: In function 'int main()':
trener.cpp:34:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |    for(int l = 0; l < s[i][j].size(); l++)
      |                   ~~^~~~~~~~~~~~~~~~
trener.cpp:37:25: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   37 |    for(int l = 0; l + 1 < s[i][j].size(); l++)
      |                   ~~~~~~^~~~~~~~~~~~~~~~
trener.cpp:40:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   40 |    for(int l = 1; l < s[i][j].size(); l++)
      |                   ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...