Submission #732934

#TimeUsernameProblemLanguageResultExecution timeMemory
732934vjudge1Trener (COCI20_trener)C++17
55 / 110
82 ms2500 KiB
#include<bits/stdc++.h> #define int long long #define MOD 1000000007 #define all(x) x.begin(),x.end() #define ff first #define ss second #define pb push_back #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); using namespace std; const int x=29; int p[1505]; int add(int x,int y){ return ((x+y)%MOD+MOD)%MOD; } int mul(int x,int y){ return (x*y)%MOD; } int fp(int a,int b){ if(b==0)return 1; int t=fp(a,b/2); t=(t*t)%MOD; if(b%2)return (t*a)%MOD; return t; } int32_t main(){ fast; p[0]=1; for(int i=1;i<=1500;i++)p[i]=mul(p[i-1],x); int n,m; cin>>n>>m; map<int,int>mp; for(int i=0;i<n;i++){ map<int,int>mp2; for(int j=0;j<m;j++){ string s; cin>>s; int a=0; for(int k=0;k<s.size()-1;k++){ a=add(a,mul(s[k]-'a'+1,p[k])); } if(i==0){ mp2[add(a,mul(s.back()-'a'+1,p[(int)s.size()-1]))]++; mp2[add(a,mul(s.back()-'a'+1,p[(int)s.size()-1]))]%=MOD; continue; } mp2[add(a,mul(s.back()-'a'+1,p[(int)s.size()-1]))]=add(mp2[add(a,mul(s.back()-'a'+1,p[(int)s.size()-1]))],add(mp[a],mp[add(mul(s.back()-'a'+1,p[(int)s.size()-2]),mul(fp(x,MOD-2),add(a,-(s[0]-'a'+1))))])); if(a==add(mul(s.back()-'a'+1,p[(int)s.size()-2]),mul(fp(x,MOD-2),add(a,-(s[0]-'a'+1))))){ mp2[add(a,mul(s.back()-'a'+1,p[(int)s.size()-1]))]=add(mp2[add(a,mul(s.back()-'a'+1,p[(int)s.size()-1]))],-mp[a]); } } mp.clear(); mp=mp2; } int ans=0; for(auto i:mp)ans=add(ans,i.ss); cout<<ans<<endl; }

Compilation message (stderr)

trener.cpp: In function 'int32_t main()':
trener.cpp:45:17: 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]
   45 |    for(int k=0;k<s.size()-1;k++){
      |                ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...