Skip to content

Commit

Permalink
Merge pull request #113 from euyogi/master
Browse files Browse the repository at this point in the history
Correção: ordem dos loops de h() devem ser reversas
  • Loading branch information
edsomjr authored Dec 20, 2024
2 parents f56ea42 + 03113e8 commit 0290ce6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
5 changes: 3 additions & 2 deletions Strings/slides/hashes/codes/double_hash.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ int f(char c) { return c - 'a' + 1; }

int hi(long long pi, long long qi, const string& s)
{
int N = s.size();
long long ans = 0;

for (auto c : s)
for (int i = N - 1; i >= 0; --i)
{
ans = (ans * pi) % qi;
ans = (ans + f(c)) % qi;
ans = (ans + f(s[i])) % qi;
}

return ans;
Expand Down
5 changes: 3 additions & 2 deletions Strings/slides/hashes/codes/h.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@ int f(char c)

int h(const string& s)
{
int N = s.size();
long long ans = 0, p = 31, q = 1'000'000'007;

for (auto c : s)
for (int i = N - 1; i >= 0; --i)
{
ans = (ans * p) % q;
ans = (ans + f(c)) % q;
ans = (ans + f(s[i])) % q;
}

return ans;
Expand Down
7 changes: 4 additions & 3 deletions Strings/slides/hashes/codes/subs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ int f(char c)

int h(const string& s)
{
int N = s.size();
ll ans = 0;

for (auto c : s)
for (int i = N - 1; i >= 0; --i)
{
ans = (ans * p) % q;
ans = (ans + f(c)) % q;
ans = (ans + f(s[i])) % q;
}

return ans;
Expand Down Expand Up @@ -72,8 +73,8 @@ int h(int i, int j, const vector<ll>& ps, const vector<ll>& is)

int unique_substrings(const string& s)
{
set<ll> hs;
int N = s.size();
set<ll> hs;

auto ps = prefixes(s);
auto is = inverses(s.size());
Expand Down

0 comments on commit 0290ce6

Please sign in to comment.