Submission #269734

#TimeUsernameProblemLanguageResultExecution timeMemory
269734mayhoubsalehSavez (COCI15_savez)C++14
120 / 120
134 ms33644 KiB
#include <bits/stdc++.h> #define ll long long #define pb push_back #define left 2*i+1 #define righ 2*i+2 #define mid (l+r)/2 #define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); using namespace std; const ll maxn=1e5+100; const ll inf=1e9+10; const ll mod=1e9+7; const ll base=27; ll n;vector<string>s; unordered_map<ll,ll>dp; ll ans; int main() { IOS cin>>n; s.resize(n); for(ll i=0;i<n;i++)cin>>s[i]; for(ll i=0;i<n;i++){ ll curans=1; ll pre=0,suf=0,b=1; for(ll l=0,r=s[i].size()-1;l<s[i].size();l++,r--){ pre=pre*base%mod; pre=(pre+(s[i][l]-'A'+1))%mod; suf=(suf+(s[i][r]-'A'+1)*b%mod)%mod; b=b*base%mod; if(pre==suf){ curans=max(curans,dp[pre]+1); } } dp[pre]=max(dp[pre],curans); ans=max(ans,curans); } cout<<ans<<endl; return 0; }

Compilation message (stderr)

savez.cpp: In function 'int main()':
savez.cpp:29:37: 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]
   29 |         for(ll l=0,r=s[i].size()-1;l<s[i].size();l++,r--){
      |                                    ~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...