Submission #858406

#TimeUsernameProblemLanguageResultExecution timeMemory
858406Tenis0206Palindromic Partitions (CEOI17_palindromic)C++11
100 / 100
117 ms20864 KiB
#include <bits/stdc++.h> using namespace std; const int nmax = 1e6; const int b = 27; const int Mod = 1e9 + 7; string s; int h[nmax + 5]; int put[nmax + 5]; int get_hash(int st, int dr) { return (h[dr] - 1LL * h[st - 1] * put[dr - st + 1] % Mod + Mod) % Mod; } int solve(int st, int dr) { if(st > dr) { return 0; } for(int len=1;st + len - 1 < dr - len + 1;len++) { bool ok = (get_hash(st,st+len-1) == get_hash(dr-len+1,dr)); if(ok) { return 2 + solve(st + len, dr - len); } } return 1; } void solve_test() { cin>>s; s = "#" + s; put[0] = 1; for(int i=1;i<s.size();i++) { put[i] = 1LL * put[i - 1] * b % Mod; h[i] = (1LL * h[i - 1] * b + s[i] - 'a' + 1) % Mod; } cout<<solve(1,s.size() - 1)<<'\n'; } int main() { ios::sync_with_stdio(false); cin.tie(0); #ifdef home freopen("nr.in","r",stdin); freopen("nr.out","w",stdout); #endif // home int t; cin>>t; for(int test=1;test<=t;test++) { solve_test(); } return 0; }

Compilation message (stderr)

palindromic.cpp: In function 'void solve_test()':
palindromic.cpp:41:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::__cxx11::basic_string<char>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |     for(int i=1;i<s.size();i++)
      |                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...