Submission #113848

#TimeUsernameProblemLanguageResultExecution timeMemory
113848FrankenweenSavez (COCI15_savez)C++17
0 / 120
104 ms53696 KiB
#ifdef LOCAL #define _GLIBCXX_DEBUG #endif #include <bits/stdc++.h> #define ull unsigned long long #define pll pair<ll, ll> #define mp make_pair #define ll long long #define pb push_back #define deb(x) cout << #x << " = " << x << endl #define all(x) x.begin(), x.end() #define ld long double const ll mod1 = (ll)1e9 + 7; const ll mod2 = (ll)1e9 + 9; const ll BASE = 47; const ll inf = (ll)1e18; const long double e = 2.718281828459; const long double pi = 3.141592653; const ld EPS = 1e-9; using namespace std; template <class T> istream& operator>>(istream &in, vector<T> &arr) { for (T &cnt : arr) { in >> cnt; } return in; }; void solve() { ll n; cin >> n; vector<string> arr(n); cin >> arr; ll LEN = 2000000 + 1; vector<ll> p1(LEN); p1[0] = 1; for (int i = 1; i < LEN; i++) { p1[i] = (p1[i - 1] * BASE) % mod1; } vector<vector<ll>> hash1(n); for (int i = 0 ; i < n; i++) { hash1[i].resize(arr[i].size() + 1); ll h1 = 0; ll j = 1; for (auto c : arr[i]) { h1 = (h1 * BASE + c - 'A' + 1) % mod1; hash1[i][j] = h1; j++; } arr[i].clear(); } map<ll, ll> dp; ll answer = 0; for (int i = 0; i < n; i++) { ll mx = 0; ll len = 1; while (len <= arr[i].size()) { ll h1 = (hash1[i].back() - hash1[i][arr[i].size() - len] * p1[len]) % mod1; if (h1 < 0) { h1 += mod1; } if (h1 == hash1[i][len] and dp.count(h1) != 0) { mx = max(mx, dp[h1]); } len++; } dp[hash1[i].back()] = mx + 1; answer = max(answer, mx + 1); } cout << answer; } int main() { #ifndef LOCAL ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); #else freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout); #endif cout.precision(30); ll seed = time(0); //cerr << "Seed: " << seed << "\n"; srand(seed); solve(); return 0; }

Compilation message (stderr)

savez.cpp: In function 'void solve()':
savez.cpp:63:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         while (len <= arr[i].size()) {
                ~~~~^~~~~~~~~~~~~~~~
#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...