Submission #632395

#TimeUsernameProblemLanguageResultExecution timeMemory
632395NeosSavez (COCI15_savez)C++14
0 / 120
38 ms65536 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; using ii = pair<ll, ll>; #define fastIO ios::sync_with_stdio(0); cin.tie(0); #define fi first #define se second #define pb push_back #define numBit(x) (__builtin_popcountll(1ll * (x))) #define getBit(x, i) ((x) >> (i) & 1) #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define MASK(x) 1ll << (x) template<class X, class Y> bool minimize(X &x, const Y &y) { X eps = 1e-9; if (x > y + eps) { x = y; return true; } else return false; } template<class X, class Y> bool maximize(X &x, const Y &y) { X eps = 1e-9; if (x + eps < y) { x = y; return true; } else return false; } const int N = 2e6 + 7; int n; ll val[N]; string s[N]; map<ll, int> mp; struct Hash { const int base[2] = {311, 10007}, MOD = 1e9 + 7; string s; ll n; vector<vector<ll>> hsh, hsh2, pw; void init(string x) { s = x; n = sz(s); s = ' ' + s; hsh.resize(n + 3, vector<ll>(2, 0)); hsh2.resize(n + 3, vector<ll>(2, 0)); pw.resize(n + 3, vector<ll>(2, 1)); for(int i = 1; i <= n; i++) { for (int j = 0; j < 2; j++) { pw[i][j] = pw[i - 1][j] * base[j] % MOD; hsh[i][j] = (hsh[i - 1][j] * base[j] + s[i]) % MOD; } } for (int i = n; i >= 1; i--) for (int j = 0; j < 2; j++) hsh2[i][j] = (hsh2[i + 1][j] * base[j] + s[i]) % MOD; } ll get(int l, int r) { ll v1 = (hsh[r][0] - hsh[l - 1][0] * pw[r - l + 1][0] % MOD + MOD) % MOD; ll v2 = (hsh[r][1] - hsh[l - 1][1] * pw[r - l + 1][1] % MOD + MOD) % MOD; return (v1 << 31) | v2; } ll getRev(int l, int r) { ll v1 = (hsh2[l][0] - hsh2[r + 1][0] * pw[r - l + 1][0] % MOD + MOD) % MOD; ll v2 = (hsh2[l][1] - hsh2[r + 1][1] * pw[r - l + 1][1] % MOD + MOD) % MOD; return (v1 << 31) | v2; } } H[N]; signed main() { fastIO; if (fopen("test.inp", "r")) { freopen("test.inp", "r", stdin); freopen("test.out", "w", stdout); } cin >> n; for (int i = 1; i <= n; i++) { cin >> s[i]; H[i].init(s[i]); val[i] = H[i].get(1, sz(s[i])); } ll ans = 0; for (int i = 1; i <= n; i++) { ll tmp = 0; for (int j = 1; j <= sz(s[i]); j++) { ll pre = H[i].get(1, j); ll suf = H[i].get(sz(s[i]) - j + 1, sz(s[i])); if (pre == suf) maximize(tmp, mp[pre] + 1); } maximize(ans, tmp); mp[val[i]] = tmp; } cout << ans; }

Compilation message (stderr)

savez.cpp: In function 'int main()':
savez.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen("test.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
savez.cpp:83:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   83 |         freopen("test.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#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...