Submission #530959

#TimeUsernameProblemLanguageResultExecution timeMemory
530959Tenis0206Trener (COCI20_trener)C++11
22 / 110
887 ms2180 KiB
#include <bits/stdc++.h> #define int long long using namespace std; const int Mod = 1e9 + 7; const int Mh = 666013; const int b = 29; int n,k; int dp[1505]; string s[1505]; map<int,int> dps,fc; signed main() { ios::sync_with_stdio(false); cin.tie(0); cin>>n>>k; for(int j=1; j<=k; j++) { cin>>s[j]; int Hash = 0; for(auto it : s[j]) { Hash = (1LL * Hash * b + (it - 'a' + 1)) % Mh; } ++dps[Hash]; } for(int i=2; i<=n; i++) { for(int j=1; j<=k; j++) { dp[j] = 0; } for(int j=1; j<=k; j++) { cin>>s[j]; fc.clear(); for(int st=0; st<s[j].size(); st++) { int Hash = 0; for(int dr=st; dr<s[j].size(); dr++) { Hash = (1LL * Hash * b + (s[j][dr] - 'a' + 1)) % Mh; if(!fc[Hash]) { dp[j] += dps[Hash]; dp[j] %= Mod; } ++fc[Hash]; } } } dps.clear(); for(int j=1; j<=k; j++) { int Hash = 0; for(auto it : s[j]) { Hash = (1LL * Hash * b + (it - 'a' + 1)) % Mh; } dps[Hash] += dp[j]; dps[Hash] %= Mod; } } int rez = 0; for(int j=1; j<=k; j++) { rez += dp[j]; rez %= Mod; } cout<<rez<<'\n'; return 0; }

Compilation message (stderr)

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